简体   繁体   中英

git squash when merging branches

i am wondering what happens if you squash between branches and push/pull from remote in between.

DEVELOPER 1
1. $ git checkout foo
2. $ git commit -m 'changed file' file.txt
   $ git commit -m 'changed another file' file2.txt
3. $ git push

DEVELOPER 2
4. $ git checkout foo
5. $ git pull    // gets commits from 2. above
6. $ git checkout bar
7. $ git merge foo
8. $ git rebase -i HEAD~3

in 1 - 3 -- i make some local changes to some files, commit them separately, then push. in 4 - 8 -- someone else pulls my commits, checks out another branch, merges the first one, then tries to squash the commit in the merge.

would this mess up history, is it "bad"?

git rebase -i HEAD~3 would replay commits (squashed or not) in the bar branch, leaving the ones referenced by the branch foo untouched.

It is bad if your branch bar was already pushed (see " git rebase develop branch "), because you would need to force push it and make other developers on bar in trouble.

But it is also bad in that it will duplicate commit contents (between those of foo branch, and the one(s) squashed on bar , making any future merge from foo to bar to apply again commits 2 and 3.
That is where the option -p ( --preserve-merges ) of a rebase can come in handy, in order to preserve the parents of a merge. But that might not be compatible with what you want to do (squash).

In general, try to not modify a public history that you just pulled (like commit 2 and 3 on branch foo )

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