繁体   English   中英

如何将所有文件从一个分支合并到另一个分支,但一个文件除外

[英]how to merge all files from one branch to another branch but except one file

认为,

一科:

file1,
No-add-another-branch
file3

另一个分支:

file1, 
file2, 
....

我想将一个分支中的所有文件合并到另一个分支中,除了“No-add-another-branch”文件。

我可以将“No-add-another-branch”文件移动到某个地方并将一个分支合并到另一个分支,但我正在寻找一种快捷方式。 或 git 方式。

  1. 正常合并一个分支到另一个分支(包括No-add-another-branch
  2. No-add-another-branch阶段删除(使用git rm No-add-another-beanch
  3. 修改合并提交( git commit --amend

另一种方法是在合并之前删除临时分支中的文件。 这会创建一个额外的提交,但会使合并更清晰,并且历史记录将更容易阅读。

  1. git checkout -b tmp OneBranch
  2. git rm No-add-another-branch后跟git commit -m 'Remove the file before merging
  3. git checkout AnotherBranchgit merge tmp
  4. git branch -d tmp

历史应该是这样的:

 o--o--o--o Another Branch
         /
        o Remove the file before merging
       /
o--o--o One Branch

如果您不想删除文件,而是希望保持文件不变,您可以将第一种方法的步骤 2 替换为git checkout AnotherBranch^ -- No-add-another-branch (即,在合并之前恢复其先前版本) ,或将第二种方法的步骤 2 替换为git checkout AnotherBranch -- No-add-another-branch followed by git commit -m 'Make the file equal to Another Branch before merging'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM