Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Git分支中删除功能,然后将其重新合并?_Git_Github_Merge_Branch_Branching And Merging - Fatal编程技术网

从Git分支中删除功能,然后将其重新合并?

从Git分支中删除功能,然后将其重新合并?,git,github,merge,branch,branching-and-merging,Git,Github,Merge,Branch,Branching And Merging,假设我有两个分支: 发展 生产 我现在在两个分支上都有一个文件,但我想从生产分支中删除一些元素,但将其保留在我的开发分支中 因此,我进入并向我的生产分支承诺删除该元素 稍后,我决定将这些元素添加回生产分支(特别是从更新的开发分支中的元素) 如果我只是简单地进行合并,那么这些元素将不会被添加回。在这种情况下,更新生产分支的最佳方法是什么?没有一种通用的方法来删除一个分支中的数据,然后通过另一个分支将该数据合并回来,同时在各自的分支中隔离其他更改(稍后将详细介绍)。但是,可能有一种方法专门针对您的工

假设我有两个分支:

  • 发展
  • 生产
  • 我现在在两个分支上都有一个文件,但我想从生产分支中删除一些
  • 元素,但将其保留在我的开发分支中

    因此,我进入并向我的生产分支承诺删除该元素

    稍后,我决定将这些
  • 元素添加回生产分支(特别是从更新的开发分支中的
  • 元素)


    如果我只是简单地进行合并,那么这些元素将不会被添加回。在这种情况下,更新生产分支的最佳方法是什么?

    没有一种通用的方法来删除一个分支中的数据,然后通过另一个分支将该数据合并回来,同时在各自的分支中隔离其他更改(稍后将详细介绍)。但是,可能有一种方法专门针对您的工作流程

    显式解 如果
    master
    分支中没有其他更改,则需要查找以下内容:

    git checkout master
    vim <file where you delete lis>
    git add <file>
    git commit
    
    git checkout development
    git merge master
    git revert master
    
    可能还有其他解决方案,但它们更具组织性,或者需要其他工具,而不仅仅是简单的Git。

    Git revert
    git checkout master
    git merge development
    
    git revert <id of the commit where you deleted li>