Background:
I have a feature branch A that is one commit ahead of my development branch:
3 (develop, origin/develop)
| 2 (A, origin/A) some feature branch commit
|/
1 some commit
Then I rebase A on develop (git checkout A
, git rebase develop
), so I get:
2' (A) some feature branch commit
|
3 (develop, origin/develop)
| 2 (origin/A) some feature branch commit
|/
1 some commit
Now I can no longer push A
to origin
as Git will reject a non-fast forward commit. It tells me to first pull the remote changes.
When I do so and then push, I end up with the following history:
4 (A, origin/A) merged origin/A into A
|\
2'| some feature branch commit
| |
3 | (develop, origin/develop)
| 2 (origin/A) some feature branch commit
|/
1 some commit
I end up with a history containing the 2
commit twice -- technically different commits although they do the same thing.
Questions
Rebasing a branch on another "re-applies" (fairly smartly, these days) the commits of the currently checked out branch on top of the tip of the target. So, yes, if you do it over and over again then you will keep your current branch up to date.
Changing older or multiple commits. To modify older or multiple commits, you can use git rebase to combine a sequence of commits into a new base commit. In standard mode, git rebase allows you to literally rewrite history — automatically applying commits in your current working branch to the passed branch head.
When you save and exit the editor, Git applies all two changes and then puts you back into the editor to merge the three commit messages: # This is a combination of commits. # The first commit's message is: Removed most clearfixs in templates # This is the 2nd commit message: Removed most clearfixs in templates.
A rebase is rewriting history - to avoid trouble don't rebase things that are pushed.
You can push --force
while A
is checked out. origin/A
history will be overwritten with your version of A
. Note that this will require manual intervention from other developers in their repos afterwards.
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