简体   繁体   中英

git rebase develop branch

Sorry, just another "rebase" question but I'm confused about that.
Form time to time I push my commits on the develop branch to remote (origin). Now one thing always mentioned with rebase is: "never rebase if you have pushed your changes".
This means, I could never ever rebase my develop branch, only merge it?

Working on a feature-branch is clear, if I haven't pushed that, I could rebase instead of merge. My question only points to the develop branch.

You can rebase (and force the next push) provided nobody has cloned/updated his/her own local repo with your remote repo.
If other people have pulled from your remote repo, and you force push your rebased branch, you publish a new history, forcing them to a more complex operation of reset (they have to reset their own local branch to the new remote branch history, and then reapply their own commits).
For a public remote repo, a forced push can lead to problems ;) .

Read "The Perils of Rebase" in the "Pro Git" book — it provides nice explanation with pictures. The git-rebase manual page also contains the section "Recovering from upstream rebase") which makes you appear in the shoes of everyone who might be affected by your rebase. ;-) Nice ASCII-art is included as well.

And no, "never rebase what was pushed to a public repo" should not be taken as a dogma: sometimes, it's a valid approach, if such rebasing is clearly articulated to other users of your public repository. For instance, see what the current Git maintainer says about his "pu" branch (this memo is somewhat outdated, and newer versions of this text do not mention rebasing directly, so I decided to link to this older copy).

It does not matter what "kind" of branch you have (after all it's just a concept, for git, a branch is a branch). Once you pushed any changes, don't do a rebase, otherwise the hash of the commit will change.

You should not rebase the pushed commits. However, it's perfectly fine to rebase ( -i ) commits that have not been pushed.

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