ksylor / ohshitgit

The official home of Oh Shit, Git!?!
1.34k stars 162 forks source link

Addition: git commit --fixup [sha] / git rebase -i --autosquash [sha] #75

Open mikeappell opened 4 years ago

mikeappell commented 4 years ago

One of my favorite git tricks, this allows you to amend an old commit when you realize there's small changes needed, like fixing a typo or a small bug.

Note that this should only be done on a branch, or for commits which you haven't yet pushed, as this is re-writing history. Thus, if you've already pushed the commit you're editing, you'll need to force-push them the second time.

Steps are:

Note that if you're fixing up multiple commits simultaneously, the final 'autosquash' rebase will need to be of the oldest commit being fixed up.

Also note that this can potentially cause merge conflicts if the changes aren't small and conflict with other intervening changes. So use sparingly.

Good article here: https://thoughtbot.com/blog/autosquashing-git-commits

mdavis-xyz commented 3 years ago

When I try this, the second command tells me:

fatal: invalid upstream '^6b3330228692fa31c1358a763887a2627d012f0f'

Is the [sha] in the second command supposed to be a different one to the first?