What I did to reproduce the consequence of misuse of git merge commit
Git is a powerful tool. More power means more responsibility.
We use git in our project. There are several developers so the commits are quite frequent.
Symptom:
Sometimes we see our changes and corresponding commits disappears after some developer do their merge commit. Their merge commit seems to have reverted away commits which has been done earlier by others.
In the commit log we see the guilty merge commit behavior very strange: It has two parent A and B. A is the guilty developer's local commit branch, and B is the other developer's commits branch. Strangely the merged commit would choose the status of A instead B in the merged results for files that has been changed and committed in commit branch B(which is other developers' commit). So the consequence is that after the merge commit, the changes has been committed and pushed by other developer will "gone"! The status of the files from other developers' commit are "reverted" back to long time ago. (which is actually the status of files of this guilty developer A's local status before he did the pull)
Steps to reproduce the problem:
1. User1 create initial commit contians 4 files A,B,C,D and pushed them.
2. User2 do pull so to sync A,B,C,D. Now User1 and User2 have the same status.
3. User2 modify file W and commit modified W locally. (But not pushed yet)
4. User1 also modified file W and commit the modified file W locally, and pushed!
5. User2 now do a pull before he can do a push. He get conflict on file W. (Screenshot1)
6. User2 want to edit the conflicted file W manually. (On screenshot1 he click OK)
7. User2 edit the conflicted file W locally and resolve the conflict.
8. User2 try to commit his locally change again. (Screenshot 2)
9. User2 choose to not commit modified files X and Y.
10. User2 committed change for W and pushed.
11. User1 now do a pull and view the log. He sees his changes for X and Y has been reverted back by the merge commit made by User2.
Extra: View the log for only file X and Y you will not able to even see the commit made by User1 at step 4 unless you choose “follow rename”.
评论
发表评论