ProTip: A better git log - https://coderwall.com/p/euwpig
- commits
git show HEAD
git rev-list HEAD --parents --max-count 5
git rev-list master --parents --max-count 5
- trees
git ls-tree HEAD
- blobs
ls .\.git\objects\
- refs
git branch
git branch --all
less .\.git\info\refs
less .\.git\info\refs | Where { -not $_.Contains("remotes") }
git lg master
git lg
git help rebase
"Forward-port local commits to the updated upstream head"
In Plain English
"Reapply a series of commits to a different point in history"
git rebase master my-feature-branch
- update local branch as mainline dev changes
- you're embarassed about your branch history
- you're averse to merge commits
What's bad about this
- it's hella intimidating
- it screams when things go wrong
- ermagherd it's changing my history
git log -n 9 --oneline
git rebase master shiftkey/rework-build-script
💥
git log -n 2 --pretty=oneline
git rebase --abort
phew
git rebase master shiftkey/rework-build-script
git mergetool
git rebase --continue
lather, rinse, repeat
git log -n 9 --oneline
git log -n 9 --oneline origin/shiftkey/rework-build-script
The commits are still around, but their hashes have changed? Why?
Git commit identifiers (SHA1) are generated based on a number of factors
- author
- timestamp
- tree and blob content
- commit message
- parent
But hang on, what about collisions?
If all 6.5 billion humans on Earth were programming, and every second, each one was producing code that was the equivalent of the entire Linux kernel history (1 million Git objects) and pushing it into one enormous Git repository, it would take 5 years until that repository contained enough objects to have a 50% probability of a single SHA-1 object collision.
Or:
A higher probability exists that every member of your programming team will be attacked and killed by wolves in unrelated incidents on the same night.
http://4.bp.blogspot.com/-d3coUm8yovI/UlykDPFGeHI/AAAAAAAABJM/pRwt_GJz7wQ/s1600/dirtyharry.jpg
git rebase master shiftkey/rework-build-script -i
- git generates a file containing the commits you are about to apply
- git asks you to check and edit the file if things aren't cool
- if you do nothing here (close the file), then it's doing a normal rebase
What can I do?
pick
- do nothingamend
- change the commit messagesquash
- combine this commit with the previous one (amend message)fixup
- combine this commit with the previous one (use previous message)edit
- pause the rebase here (POWER USER MODE)exec
- run an arbitrary command against it (SUPER POWER USER MODE)
Oh, and you can remove lines from the file. What does that do? Delete them from the new branch (phwoar!)
So here's my sort of workflow:
- amend commits - get messages right
- reorder commits - easiest way to see what's broken
- fixup commits - i used to be a fan of squash, but not so much these days