本文介绍了Git合并删除应该保留的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

合并分支时,Git会自动删除不应删除的代码。基本上我们有两个主要分支:MASTER和DEVELOP。
$ b


  • MASTER有我们的PRODUCTION代码。

  • DEVELOP有我们当前的开发场景。



所有新代码都在其他分支中开始,通常指的是问题或新功能。我们的日常活动是:(当前分支开发):

  git pull origin开发
git checkout -b某些功能。

这两位程序员都添加了一些代码和提交(我们每天提交多次)。在一天结束的时候,我们尝试合并我们的东西。首先,程序员A进行推送。

  git add。 
git commit -m'push'之前的最后一次提交'
git checkout develop
git合并某些功能
git push develop

到目前为止没有问题。然后程序员B试图做同样的事情,但他必须先做出拉!

  git add。 
git commit -m'push'之前的最后一次提交'
git checkout develop
git merge some-feature-b
git pull origin develop

Git成功读取并合并origin / develop。有些冲突可能发生,冲突没有问题。我们的问题是,Git删除了不应该被删除的代码,我们没有机会告诉它不要。



我们做错了什么?

解决方案

我会先取出,然后合并。

  git checkout some-feature 
#work
git add。
git commit -m'push'之前的最后一次提交'

git checkout develop
git pull develop
git merge some-feature

这样,您就可以合并您的本地某些功能分支-date develop 分支。


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?

解决方案

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.

这篇关于Git合并删除应该保留的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 04:24