code> | |
# 1. Add line4 with a typo, commit | |
$ echo "line44" >> new.txt | |
$ git commit -a -m "Added new.txt line4." | |
# 2. Note our history | |
$ git l | |
# sha-a "Added new.txt line4." | |
# 3. Fix our typo, amend the commit | |
$ sed -i s/line44/line4/ new.txt | |
$ git commit -a --amend | |
# 4. Note history, there is one, different "line4" commit | |
$ git l | |
# sha-a' "Added new.txt line4." | |
# commit sha = hash(timestamp, author, message, repo contents) | |
# amending always changing the last commit's sha | |
# 5. Change new, new-b in separate commits | |
$ echo "line5" >> new.txt | |
$ git commit -a -m "Added new line5." | |
$ echo "line3" >> new-b.txt | |
$ git commit -a -m "Added new-b line3." | |
# 6. Rebase to re-order the commits | |
$ git rebase -i HEAD~2 | |
# oldest is listed first | |
# pick sha-a "Added new line5." | |
# pick sha-b "Added new-b line3." | |
# Change order of lines: | |
# pick sha-b "Added new-b line3." | |
# pick sha-a "Added new line5." | |
# Save/quit | |
# 7. Note history | |
$ git l | |
# 8. We screwed up, pretend line3/line5 never happened | |
$ git reflog | |
# Shows what "HEAD" was X commits ago | |
# Find 'commit (amend): Added line4' | |
$ git reset --hard HEAD@{N} | |
$ cat new.txt # no line5 | |
$ cat new-b.txt # new line3 |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND