如何将更改合并到单个文件中,而不是合并提交?

503

我有两个分支(A和B),我想将A分支中的一个文件与B分支中相应的一个文件合并。


2
已在此处讨论:https://dev59.com/9nRB5IYBdhLWcg3w-789 - positron
39
那篇帖子的大多数回复都是关于如何有选择性地合并“提交”而不是“文件”。这使得被选中的答案不正确。问题仍未得到回答。 - user153275
2
可能是如何使用git-merge选择性地合并文件?的重复问题。 - phuclv
12个回答

0
如果在错误的合并之后需要执行此操作,您可以执行以下操作:
# If you did a git pull and it broke something, do this first
# Find the one before the merge, copy the SHA1
git reflog
git reset --hard <sha1>

# Get remote updates but DONT auto merge it
git fetch github 

# Checkout to your mainline so your branch is correct.
git checkout develop 

# Make a new branch where you'll be applying matches
git checkout -b manual-merge-github-develop

# Apply your patches
git checkout --patch github/develop path/to/file
...

# Merge changes back in
git checkout develop
git merge manual-merge-github-develop # optionally add --no-ff

# You'll probably have to
git push -f # make sure you know what you're doing.

-2
git checkout <target_branch>
git checkout <source_branch> <file_path>

4
难道 Pawel 的回答 不已经解释了这个吗? - Eric Aya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接