在 git 合并期间如何接受特定文件夹中的所有远程文件?
How can I accept all remote files in a specific folder during a git merge?
我们在 Windows Powershell 上使用 posh-git 进行源代码控制。
我们将一些构建的程序集存储在我们的 git 存储库中,这是一个令人羡慕的位置。我知道所有关于为什么你不应该那样做的布道,但我们现在必须忍受它。值得庆幸的是,他们在一个单独的解决方案中,但有时两个人同时在他们自己的分支中处理该解决方案,最后一个人开始处理合并冲突。当然,这个过程看起来像这样:
- A 将他们的更改放在 develop 上。
- B 合并了这些更改,其中包括程序集和
更新源代码。
- B 解决冲突,因为必须确认每个冲突的版本
他们想保留的集会。这既烦人又费时,
并且也没有必要,因为 B 将在之后重建组件
无论如何合并源代码。
- B 重建程序集并进行新的提交以完成
合并。
这些程序集位于我们 Repo 的一个文件夹中:/Source/Foundation Assemblies/
B 不能只接受来自远程的 all 更改,因为他们的分支可能有冲突的更改,但只接受 "take theirs" 或 "take mine" 仅用于 /Source/Foundation 程序集/文件夹 。这可以用 git 来完成吗?
命令行示例会有所帮助。通常,合并只是:
git merge develop
我在想也许可以 .git忽略 /Source/Foundation Assemblies/ 文件夹,然后在合并后将其从 .gitignore 中删除,但那是三个步骤。如果我们可以通过命令行一次完成,那就是 太棒了!!!
感谢任何帮助!
你可以git merge develop -X theirs
,所有冲突都将使用远程分支的副本。
编辑:回顾你的问题,我发现你只想对特定的子文件夹使用 "theirs"。在这种情况下,在 git merge develop
之后执行 git checkout --theirs /Source/Foundation Assemblies/
。这将用 "theirs" 替换该文件夹的内容。然后 git add /Source/Foundation Assemblies/
就可以了。
您可以使用多种合并策略:
解决
This can only resolve two heads (i.e. the current branch and another branch you pulled from) using a 3-way merge algorithm. It tries to carefully detect criss-cross merge ambiguities and is considered generally safe and fast.
递归
This can only resolve two heads using a 3-way merge algorithm. When there is more than one common ancestor that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. This has been reported to result in fewer merge conflicts without causing mismerges by tests done on actual merge commits taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames. This is the default merge strategy when pulling or merging one branch.
The 'recursive' strategy can take the following options:
我们的
This option forces conflicting hunks to be auto-resolved cleanly by favoring 'our' version. Changes from the other tree that do not conflict with our side are reflected to the merge result. For a binary file, the entire contents are taken from our side.
This should not be confused with the 'ours' merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring 'our' history contains all that happened in it.
他们的
This is the opposite of 'ours'.
甚至更多,但这些是主要的。
在您的案例中,"right" 方法是在提交合并之前重建程序集。我不明白你为什么不这样做。以下步骤应该有效:
- 解决并
git add
所有冲突的来源。那么合并期间发生的任何事情都不应该影响你提交的内容。
- 删除冲突的程序集文件。无需对他们的 git 信息进行任何操作,只需删除文件
- 构建程序集。
git add
准备好的程序集。
- 然后提交。您得到的是合并,其中包括本地和远程更改。
编辑:试试这个:
git rm --force -r <dirname>
- 运行 你的 mergetool,现在应该提到二进制文件(
kdiff3
没有)
- 构建程序集
git add <dirname>
- 提交
我尝试了 this bash 脚本来重现我理解的案例。
我们在 Windows Powershell 上使用 posh-git 进行源代码控制。
我们将一些构建的程序集存储在我们的 git 存储库中,这是一个令人羡慕的位置。我知道所有关于为什么你不应该那样做的布道,但我们现在必须忍受它。值得庆幸的是,他们在一个单独的解决方案中,但有时两个人同时在他们自己的分支中处理该解决方案,最后一个人开始处理合并冲突。当然,这个过程看起来像这样:
- A 将他们的更改放在 develop 上。
- B 合并了这些更改,其中包括程序集和 更新源代码。
- B 解决冲突,因为必须确认每个冲突的版本 他们想保留的集会。这既烦人又费时, 并且也没有必要,因为 B 将在之后重建组件 无论如何合并源代码。
- B 重建程序集并进行新的提交以完成 合并。
这些程序集位于我们 Repo 的一个文件夹中:/Source/Foundation Assemblies/
B 不能只接受来自远程的 all 更改,因为他们的分支可能有冲突的更改,但只接受 "take theirs" 或 "take mine" 仅用于 /Source/Foundation 程序集/文件夹 。这可以用 git 来完成吗?
命令行示例会有所帮助。通常,合并只是:
git merge develop
我在想也许可以 .git忽略 /Source/Foundation Assemblies/ 文件夹,然后在合并后将其从 .gitignore 中删除,但那是三个步骤。如果我们可以通过命令行一次完成,那就是 太棒了!!!
感谢任何帮助!
你可以git merge develop -X theirs
,所有冲突都将使用远程分支的副本。
编辑:回顾你的问题,我发现你只想对特定的子文件夹使用 "theirs"。在这种情况下,在 git merge develop
之后执行 git checkout --theirs /Source/Foundation Assemblies/
。这将用 "theirs" 替换该文件夹的内容。然后 git add /Source/Foundation Assemblies/
就可以了。
您可以使用多种合并策略:
解决
This can only resolve two heads (i.e. the current branch and another branch you pulled from) using a 3-way merge algorithm. It tries to carefully detect criss-cross merge ambiguities and is considered generally safe and fast.
递归
This can only resolve two heads using a 3-way merge algorithm. When there is more than one common ancestor that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. This has been reported to result in fewer merge conflicts without causing mismerges by tests done on actual merge commits taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames. This is the default merge strategy when pulling or merging one branch.
The 'recursive' strategy can take the following options:
我们的
This option forces conflicting hunks to be auto-resolved cleanly by favoring 'our' version. Changes from the other tree that do not conflict with our side are reflected to the merge result. For a binary file, the entire contents are taken from our side.
This should not be confused with the 'ours' merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring 'our' history contains all that happened in it.
他们的
This is the opposite of 'ours'.
甚至更多,但这些是主要的。
在您的案例中,"right" 方法是在提交合并之前重建程序集。我不明白你为什么不这样做。以下步骤应该有效:
- 解决并
git add
所有冲突的来源。那么合并期间发生的任何事情都不应该影响你提交的内容。 - 删除冲突的程序集文件。无需对他们的 git 信息进行任何操作,只需删除文件
- 构建程序集。
git add
准备好的程序集。- 然后提交。您得到的是合并,其中包括本地和远程更改。
编辑:试试这个:
git rm --force -r <dirname>
- 运行 你的 mergetool,现在应该提到二进制文件(
kdiff3
没有) - 构建程序集
git add <dirname>
- 提交
我尝试了 this bash 脚本来重现我理解的案例。