问题
When merging branches, Git automatically removes code that shouldn't be removed. Basically we have two main branches: MASTER and DEVELOP.
- MASTER has our PRODUCTION code.
- DEVELOP has our current develop scenario.
All new code starts in other branches, that usually refer to the issue or new feature. The problem happens when we try to merge this feature or hotfix branch into develop.
Our daily activities is: (current branch develop):
git pull origin develop
git checkout -b some-feature.
Both programmers add some code and commits (we commit more than once daily). At the end of the day we try to merge our things. First, programmer A makes a push.
git add .
git commit -m 'last commit before push'
git checkout develop
git merge some-feature
git push develop
No problem so far. Then programmer B tries to do the same, but he has to make a pull first!
git add .
git commit -m 'last commit before push'
git checkout develop
git merge some-feature-b
git pull origin develop
Git successfully fetches and merges origin/develop. Some conflict may happen, no problem with conflicts. Our problem is that Git removes code that shouldn't be removed and we have no chance to tell it not to.
What are we doing wrong?
回答1:
I would pull first, then merge.
git checkout some-feature
# work
git add .
git commit -m 'last commit before push'
git checkout develop
git pull develop
git merge some-feature
That way, you are merging your local some-feature
branch in an up-to-date develop
branch.
来源:https://stackoverflow.com/questions/20286535/git-merge-deleting-code-that-should-stay