In my previous post, I talked about my amend and append aliases
Here I will talk about other aliases that are useful.
[alias]
wip = commit --message 'wip' --no-verify
uncommit = reset --soft "HEAD~1"
unamend = reset --soft "HEAD@{1}"
These syntaxes differ from HEAD^1, I never remember them, or what they mean. So aliases are definitely useful.
wip
commit with a simple message and bypass git hook if there are any.
How to use it
This can be used to commit:
- staged files
git add foo/bar
git wip
- file(s) passed in parameter o
git wip foo/bar
- or everything
git wip -a
The same way you may have used git commit -a
when do you need wip ?
- when you have local changes you want to commit in the current branch before switching to another.
- in some use case when rebasing, and you know you will have conflicts.
uncommit
This helps to uncommit the last committed changes.
Please note this will nuke your commit, and your commit message will be lost.
So you can use git log --format="%B" -n 1
before launching git uncommit
How to use it
git uncommit
no parameter is needed
when do you need uncommit ?
- when you used
git wip
and want to uncommit.
so you committed things, changed branch, did things, then switched back to the branch were you used git wip
.
- when you know your last commit is crap
unamend
How to use it
git unamend
no parameter is needed
when do you need unamend ?
- when you added changes to a commit, but you made a mistake
so you did something like this
git commit filea
git amend folderb fileb
here you notice you made a mistake, but you don't want to use uncommit that would nuke the commit message and first commit, you only want to restore to the state before you used git amend.
So you can simply type this.
git unamend
And you will be back to the state you were before amending.
Then you can use git reset fileb
or git reset -p
to remove some files or changes from the index.
Note: git unamend
works perfectly for reverting git append
changes, as the only difference with git amend
is the fact you may have updated the commit message or not