简体   繁体   中英

Rebasing master onto feature branch?

I recently joined a new team and on the team wiki, it asks us to do the follow git workflow

git checkout -b feature_branch
#do stuff and push if needed
git checkout master
git rebase feature_branch
git rebase -i HEAD~NUMBER_OF_COMMITS_AHEAD

This is different from the rebase workflow I've seen on basically all sources and it also seems to go against the golden rule of rebasing that I saw from this blog post https://www.atlassian.com/git/tutorials/merging-vs-rebasing . Can someone explain what could be the reasons for the workflow my team wiki suggests?

Assuming the instructions are accurate, they would appear to be executing a splice of feature into master . Suppose we start with this:

* (HEAD -> master) E
* D
| * (feature) K
| * J
|/  
* C
* B
* A

Now if we checkout master and rebase feature , we get this:

* (HEAD -> master) E
* D
* (feature) K
* J
* C
* B
* A

So the entirety of feature has been incorporated into master at the point where it split off from master . Subsequent commits on master have been moved into the future so that they come after the end of feature . J and K are spliced into the history A, B, C [splice], D, E.

It's hard to imagine what the purpose of that would be, and it's even harder to imagine what the interactive rebase at the end is supposed to accomplish.

The opposite move, however, namely to checkout feature and rebase master , would give us this:

* (feature) K
* J
* (HEAD -> master) E
* D
* C
* B
* A

That is a sensible thing to do. It brings feature up to date with the current state of master , minimizing the likelihood of conflicts later. And the interactive rebase would then make sense too, because that's your chance to clean up feature . You would then push feature and make a pull request. That is the flow that is generally followed.

So my guess is that the instructions are just a mistake. It's an easy mistake to make if you're not careful, because the sense of the operations checkout X; merge Y checkout X; merge Y is the opposite of the sense of the operations checkout X; rebase Y checkout X; rebase Y . The former means "merge Y into X", but the latter means "rebase X onto Y". I'll bet whoever wrote the instructions was confused by that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM