backtracking Link to heading
unmodifying Link to heading
before backtrack, show details of changes by using
git show HEAD
then, I made some changes to this file and then I realize that I did a silly thing.
I need to be back!!!
what I do is the following: git checkout HEAD <filename>
Then you can check git status, it back to the last commit.
reset Link to heading
what if I want to unstage / retract a commit?
use git reset <file_unstage>
using reset not only can unstage a commit, but can also ‘delete’ previous history.
git reset <xxxxxx> can go back to ‘xxxxxx’ commit.
checkout vs reset Link to heading
branching Link to heading
rebase Link to heading
say we have the following history

sometimes you are working on one feature say that is the experiment branch and some people make a change one master.
at this time, you want to test whether experiment is still working on the newest version of application.
you need rebase
$ git checkout experiment
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added staged command
the operation would do things like this

(Optional) after test, you are satisfied with experiment, you want to merge it to master, so just
$ git checkout master
$ git merge experiment
the result would be a clean linear history

if you want to reflect this in the remote repo, then do git push --force-with-lease.
Don’ts on rebase Link to heading
currently, according to my experience, I can just suggest DON’T use rebase on a remote repo. Just use rebase on local branches.
Always use merge
squash commits history Link to heading
the above works when something is changing in master, people could use git rebase -i master.
when doing so, it will ask you to edit the rebase-todo file, within which, it askes you to modify it.
you can reword, squash, and others. by doing squash, we are making it from long to short commits.