Git merge deleting code that should stay

℡╲_俬逩灬. 提交于 2020-01-14 03:41:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!