I have made a bunch of unpushed commits in my feature branch and now want to reorder and partly squash belonging commits visually. I reckon the solution somehow lies in the Git interactive, but how to invoke it?
$ git rebase --interactive --onto <the-ID-of-the-first-commit-to-rewrite>
just pops up the VI with a
noop
content followed by commented information. After exiting, my head is reset to the specified commit.
How to correctly trigger the interactive rebase for modifying the commits since a certain commit?
The interactive rebase gives you a script that it's going to run. It will start at the commit you specify on the command line ( HEAD~3 ) and replay the changes introduced in each of these commits from top to bottom. It lists the oldest at the top, rather than the newest, because that's the first one it will replay.
When you're finished making all your changes, you can run git rebase --continue . As before, Git is showing the commit message for you to edit. You can change the text ( "i cant' typ goods" ), save the file, and close the editor. Git will finish the rebase and return you to the terminal.
The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.
you should use
git rebase --interactive <sha1>
where <sha1>
should not be the sha of the first commit you want to rewrite, but the sha of the commit just before.
if your history looks like this:
pick 43576ef last commit
...
pick 5116d42 first commit to rewrite
pick cb85072 last good commit
There are two different ways to indicate the commit on which to rebase:
git rebase -i cb85072
git rebase -i 5116d42^
where
^
means the commit just before.-i
is just short for --interactive
You can also step back from your last commit by some number of commits. For example, if you want to rebase last 5 commits you can use this command:
git rebase -i HEAD~5
.
To review and rewrite the last n
commits, use:
git rebase -i HEAD~n
p, pick = use commit
f, fixup = like "squash", but discard this commit's log message
https://www.freecodecamp.org/forum/t/how-to-squash-multiple-commits-into-one-with-git-squash/13231
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With