3

我需要将几个存储库(每个存储库都从TFS转换)合并为一个。为此,我使用 git cherry-pick 命令,该命令适用于某些提交,但不适用于其他提交:

$ git status
# On branch master
nothing to commit, working directory clean
$ git diff-tree --no-commit-id --name-only -r e2d8405
Libraries/IFileTransformer/ITransformer.cs
Libraries/IFileTransformer/IFileTransformer.csproj
Libraries/IFileTransformer/IFileTransformer.csproj.vspscc
Libraries/IFileTransformer/Properties/AssemblyInfo.cs
$ git cherry-pick e2d8405
error: could not apply e2d8405... TFS changeset 2836
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
$ git status
# On branch master
# You are currently cherry-picking.
#   (fix conflicts and run "git commit")
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       deleted by them:    Libraries/IFileTransformer/ITransformer.cs
#       deleted by them:    Libraries/IFileTransformer/IFileTransformer.csproj
#       deleted by them:    Libraries/IFileTransformer/IFileTransformer.csproj.vspscc
#       deleted by them:    Libraries/IFileTransformer/Properties/AssemblyInfo.cs
#
no changes added to commit (use "git add" and/or "git commit -a")
$

我如何找出这里出了什么问题?“他们”是谁?在我看来,e2d8405 提交删除了四个文件。如果文件存在(并且确实存在),那么应用提交的问题在哪里?

$ git checkout e2d8405^
Note: checking out 'e2d8405^'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 48b5b2f... TFS changeset 2835   renamed namespace installutils to
 utils
$ md5sum IFileTransformer.csproj
9f9851dc9db3bddd1e6920631fa14e8b *IFileTransformer.csproj
$ git checkout master
Previous HEAD position was 48b5b2f... TFS changeset 2835   renamed namespace ins
tallutils to utils
Switched to branch 'master'
$ md5sum IFileTransformer.csproj
9f9851dc9db3bddd1e6920631fa14e8b *IFileTransformer.csproj
4

3 回答 3

3

尽管该提交删除了这些文件,但您有已删除版本中不存在的修改。由于这里存在冲突,在修改文件的分支和删除它们的分支之间,您需要通过表明您很乐意放弃更改并应用删除 ( git rm ...) 来解决它。完成此操作后,git commit即可创建精心挑选的提交。

于 2013-07-29T12:38:58.227 回答
1

运行git mergetool它会告诉你为什么它看到已删除文件的冲突,该文件可能在本地更改并在精心挑选的“他们”提交中删除。它希望您决定是否要保留修改后的版本或删除文件。

然后,您可以选择要对这些文件执行的操作。

于 2013-07-29T14:16:13.380 回答
-1

git 合并的工作方式是这样的:

对于每个要合并的文件,找到包含 并且存在于要合并的两个分支中的最新提交。然后搜索要合并的每个分支并查找任何后续更改,这些更改将仅出现在其中一个分支中。

  • 如果两个分支中都没有此类更改,请保持文件不变
  • 如果其中一个分支对文件进行了更改,而另一个没有,则保留有更改的分支
  • 如果两个分支都有变化,那么 git 就不能自动合并(哪些变化应该保留,哪些应该丢弃——没有人工干预就不可能说)

您所拥有的是最后一个案例,其中文件在一个分支中被删除,但在最后一次合并两个分支之后在另一个分支中已更改。

  A 1* B
   / \
  2   3
  |   |
  |   4*
  5*  |
  |   |

这里的数字是commits,*表示commit change一个我们感兴趣的文件包含在commit中。所以,在提交 1 处,我们还没有分支出来,这意味着这个提交是基本提交,是两个分支中都存在的最新提交。分支之后,每个分支都会添加一个提交,但都不包括有问题的文件。在此时合并时,文件只是在提交 1 中保持不变。然后在提交 4 时,对分支 B 中的文件进行更改。如果此时我们要将分支 B 合并到分支 A,所做的更改提交 4 中的文件将被合并到分支 A,因为它是最新的提交,并且在基本提交 (1) 之后分支 A 中的文件没有任何更改。但是在提交 5 时,该文件在分支 A 中也发生了更改。

检查分支中不包含删除的文件的文件历史记录,然后您可能会发现此分支中的提交,而不是删除它们的分支。

于 2013-07-29T13:45:15.163 回答