Useful Git Command Note (Uncompleted)
I’m taking this note to avoid googling them each time I wanted to use them.
Remove file from staging area
1 | git reset HEAD <file> |
Show diff between commits
1 | Show the difference between that COMMIT's ancestor and the COMMIT |
Display log elegantly in one line
1 | git log --graph --oneline --decorate --date=relative --all |
graph
enables you to view different branchesoneline
will format git log into one line outputdecorate
adds some highlights to branch namesall
helps you view all branches.
Rebase with git pull
I’d suggest you to rebase when git pull, this will prevent “Merge conflict” from happening. Honestly, I don’t like to handle conflicts manually.
1 | git pull --rebase |
If you want to know the difference between git pull
and git pull --rebase
, check this: Difference between git pull and git pull –rebase. The difference between git merge
and git rebase
can also be found here: What’s the difference between ‘git merge’ and ‘git rebase’?.
Squash last N commits
1 | git rebase --interactive HEAD~N |
Needless to say, it you want to squash serveral commits into one commit, this helps a lot. More detailed instructions can be found here: squashing commits with rebase.