Understanding how rebase works in git
I've used $ git pull origin master
(which is a combination of fetch
and merge
) and $ git push origin master
so far. Now I'm hearing about rebase
. I've read the documentation about it but sadly I couldn't understand how it works exactly.
Two questions:
One: What does '
(which is in the top of D
and E
) mean?
before rebase:
A <- B <- C
^ ^
D <- E <- F
after git rebase master:
A <- B <- C <- D' <- E'
two: When should not I use $ git rebase
? (also is it the same as git pull --rebase
?)
One: What does '
(which is in the top of D
and E
) mean?
The '
mean that the commits D'
and E'
have been altered from the original D
and E
by git's rebase functionality. So although they may end up with equivalent code changes (unless there are conflicts), they are not literally the same commits, precisely because they will at least have different history from D
and E
. In git, commits with different history are different by design, and they will have different hashes.
two: When should not I use $ git rebase
? (also is it the same as git pull --rebase
?)
When the result will be pushed to a branch that is already a shared remote, "shared" here meaning essentially that others have checked it out and have made at least local changes to it (or you are not sure whether others have done so).
From the git docs:
Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea: anyone downstream of it is forced to manually fix their history.
链接地址: http://www.djcxy.com/p/45102.html上一篇: 试图理解“Git Rebase”
下一篇: 了解rebase如何在git中工作