如何在git合并期间接受特定文件夹中的所有远程文件? [英] How can I accept all remote files in a specific folder during a git merge?

查看:106
本文介绍了如何在git合并期间接受特定文件夹中的所有远程文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Windows Powershell上使用posh-git来进行源代码管理。



我们在将我们的一些构建的程序集存储在我们的git repo中处于难以置信的地位。我知道所有讲道为什么你不应该这样做,但我们现在必须忍受它。值得庆幸的是,他们正处于一个单独的解决方案中,但有时候两个人同时在他们自己的分支中解决该解决方案,最后一个解决合并冲突。当然,这个过程看起来像这样:


  1. 个人A将他们的变更留在开发中。

  2. Person B合并这些更改,包括程序集和
    更新源代码。
  3. Person B解决冲突,因为必须确认每个
    程序集的哪个版本他们想保持。这是烦人的和耗时的,
    ,也是不必要的,因为Person B会在
    合并源代码之后重建程序集。

  4. Person B重建程序集并使用新的提交来完成合并

这些程序集位于我们的Repo:/ Source / Foundation文件夹中Assemblies /



因为他们的分支可能有冲突的变化,所以Person B不能仅仅从远程获得所有的变更,但是这对于仅仅仅接受/ Source / Foundation Assemblies /文件夹。这是可以用git完成的吗?



命令行示例会有帮助。通常情况下,合并只是:

  git merge develop 

我认为可以将.gitignore / Source / Foundation Assemblies /文件夹,然后在合并后从.gitignore中删除它,但这是三个步骤。如果我们可以在命令行中完成,那就是 GREAT !!!



任何帮助赞赏!

解决方案

在您的情况下,正确方法是在提交合并之前重建程序集。我不明白你为什么不这样做。以下步骤应该可行:


  1. 解析和 git add 所有冲突的来源。然后,在合并期间发生的任何事情都不应影响您提交的内容。

  2. 删除冲突的程序集文件。没有必要对他们的git信息做任何事情,只要删除这些文件即可。

  3. 构建程序集。
  4. git add
  5. code>准备好的程序集。
  6. 然后提交。你得到的是包含本地和远程更改的合并。


$ b 编辑:试试这个: p>


  1. git rm --force -r< dirname>

  2. 运行您的mergetool,现在它应该提及二进制文件( kdiff3 没有)

  3. build assemblies
  4. li>
  5. git add< dirname>

  6. commit
  7. ol>

    我尝试了这个 bash脚本来重现您的情况,因为我理解它。


    We're using posh-git on Windows Powershell for source control.

    We're in the unenviable position of storing some of our built assemblies in our git repo. I know all the sermons on why you shouldn't do that, but we have to live with it for now. Thankfully they are in a separate solution, but sometimes two people work on that solution in their own branch simultaneously, and the last one in gets to take the merge conflict. The process, of course, looks something like this:

    1. Person A lands their changes on develop.
    2. Person B merges those changes, which include both assemblies and update source code.
    3. Person B resolves conflicts, as has to confirm which version of each assembly they want to keep. This is annoying and time-consuming, and also unnecessary since Person B will rebuild the assembly after merging the source code anyway.
    4. Person B rebuilds the assemblies and makes a new commit to finish the merge.

    The assemblies are in a folder in our Repo: /Source/Foundation Assemblies/

    Person B cannot just take all changes from the remote, since their branch may have conflicting changes, but it would be helpful to just "take theirs" or "take mine" for the /Source/Foundation Assemblies/ folder only. Is this something that can be done with git?

    A command line example would be helpful. Normally, the merge would just be:

    git merge develop
    

    I was thinking it might be possible to .gitignore the /Source/Foundation Assemblies/ folder, and then remove it from the .gitignore after the merge, but that is three steps. If we could do it in one from the command line, that would be GREAT!!!

    Any help appreciated!

    解决方案

    The "right" way in your case is to rebuild the assemblies before committing the merge. I don't see why you would not do this. The steps as follows should work:

    1. resolve and git add all conflicted sources. Then whatever happens during merge should not affect what you commit.
    2. remove the conflicted assembly files. No need to do anything with their git information, just remove the files
    3. build the assemblies.
    4. git add the ready assemblies.
    5. Then commit. What you get is merge which includes both local and remote changes.

    EDIT: try this:

    1. git rm --force -r <dirname>
    2. run your mergetool, now it should now mention the binary files (kdiff3 did not)
    3. build assemblies
    4. git add <dirname>
    5. commit

    I tried this bash script to reproduce you case as I understand it.

    这篇关于如何在git合并期间接受特定文件夹中的所有远程文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆