我有两个分支(A和B),我想合并来自分支A的单个文件与来自分支B的相应单个文件。
当前回答
我的编辑被拒绝了,所以我附上了如何从远程分支处理合并更改在这里。
如果你必须在错误的合并后这样做,你可以这样做:
# 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.
其他回答
我的编辑被拒绝了,所以我附上了如何从远程分支处理合并更改在这里。
如果你必须在错误的合并后这样做,你可以这样做:
# 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.
你可以用:
git merge-file
提示:https://www.kernel.org/pub/software/scm/git/docs/git-merge-file.html
假设B是当前分支:
$ git diff A <file-path> > patch.tmp
$ git apply patch.tmp -R
注意,这只对本地文件应用更改。之后你需要做出承诺。
您可以签出要合并的文件的旧版本,将其保存在不同的名称下,然后在两个文件上运行合并工具。
eg.
B:src/common/storeTs > /tmp/store。ts(其中B是分支名称/提交/标记)
·梅尔德src /普通专卖店。ts / tmp / store ts。
我发现这种方法简单而有用:如何“合并”来自另一个分支的特定文件
事实证明,我们太努力了。我们的好朋友git checkout是完成这项工作的合适工具。 Git checkout source_branch <paths>… 我们可以简单地给git checkout特性分支A的名称和我们想要添加到主分支的特定文件的路径。
为了更好的理解,请阅读全文
推荐文章
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后
- 重命名git子模块
- 结合Git存储库的前两次提交?
- Xcode 6 gitignore文件应该包括什么?
- 我如何从现有回购的分支创建一个新的GitHub回购?