【问题标题】:Git Merge only string.xml fileGit 仅合并 string.xml 文件
【发布时间】:2020-10-06 17:07:19
【问题描述】:

git 新手!我们与两名开发人员一起为我们的产品添加了西班牙语,而团队的其他成员则继续添加其他功能。我们将西班牙语版本放入我们的开发分支,现在需要合并其他所有人的更改。我想先合并字符串表,然后以小块的形式完成其余的合并,而不是一次全部完成。

我试过了:

git checkout develop
git merge OtherBranch res\values\strings.xml

得到了结果:

merge: res\values\strings.xml - not something we can merge

提前致谢。我知道这只会合并我的英文 strings.xml,但一旦我知道我做错了什么,我应该能够从这里弄清楚。

【问题讨论】:

  • git merge-file。看看吧(git help merge-file)
  • 我不需要三向合并。我只需要将我们主要开发存储库中的字符串文件与我团队其他成员正在处理的字符串文件合并。而不是合并存储库,我只想合并存储库中已更改的 200 个文件中的一个文件。我已经阅读了 10 篇文章和博客,但没有一篇谈论合并存储库的一个文件。是这么简单不值得写,还是这么复杂,没人知道,还是这么不寻常,只是一个极端的案例?看来这需要人们每天都做。
  • 听起来你想加入很多关于 git 如何完成工作的假设。啊,不...通常您不会合并单个文件..您将单独的分支与所有需要的任何更改合并。这种情况确实存在,每隔一段时间,只需要合并单个文件中的内容而不涉及其他任何内容(因此git merge-file),但这并不是经常发生的事情。
  • 好点。添加或更改了 200 个文件,其中 60-70 个需要干预,大约 100 个合并清理。当我领导下的分支发生变化时,要解决整个问题需要数周时间。巨大的错误空间。我希望将片段一个片段(Android)合并成小块。有没有更好的方法来做到这一点?我是不是太难了?
  • 好吧....没有什么可以让你摆脱目前的状况......只是,为了未来,更频繁地合并(或变基),这样你就不必经历一个令人痛苦的合并过程。

标签: android git merge


【解决方案1】:

如果文件从未在 develop 上修改过,您可以简单地从 OtherBranch 获取版本:

git checkout develop
git checkout OtherBranch -- res\values\strings.xml
# check your 'git status', and 'git diff --cached' to review the file
# if all is ok :
git commit

注意:这不会合并内容,它会用存储在OtherBranch 中的内容完全覆盖develop 上的strings.xml 的内容。


如果您需要真正合并该文件——例如:在分支develop 上对strings.xml 进行的更改,而其他人在OtherBranch 上工作——您可以创建一个分支仅对strings.xml 进行了修改:

git checkout OtherBranch
git log -1  # write down the commit ID of current commit

# here is the fork point of develop and OtherBranch :
git merge-base develop OtherBranch
git checkout -b Translations [commit id of fork point]  # give whatever name you want to this branch
git checkout OtherBranch -- res\values\strings.xml
git commit  # just to have a reference somewhere : mention in this commit message
            # that this version comes from OtherBranch, with the commit id you saw
            # at line 2.

# you can now merge Translations into develop :
git checkout develop
git merge Translations

# or cherry-pick the single commit from Translations :
git checkout develop
git cherry-pick Translations

【讨论】:

    猜你喜欢
    • 2010-12-13
    • 2011-03-07
    • 2015-01-11
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    相关资源
    最近更新 更多