git通过两个分支之间的差异创建提交
我有两个分支,它们几乎没有相似的历史,但彼此相关 我希望在onegit commit中更改这两个选项 这些补丁之间的文件已被删除和创建,我希望补丁能够反映这一点 i、 e:以下内容不起作用:git通过两个分支之间的差异创建提交,git,Git,我有两个分支,它们几乎没有相似的历史,但彼此相关 我希望在onegit commit中更改这两个选项 这些补丁之间的文件已被删除和创建,我希望补丁能够反映这一点 i、 e:以下内容不起作用: git diff branch_a branch_b -- > patchfile git checkout branch_b git apply patchfile # deletes and adds are ignored git commit # we miss the deletes 一个
git diff branch_a branch_b -- > patchfile
git checkout branch_b
git apply patchfile # deletes and adds are ignored
git commit # we miss the deletes
一个简单的方法是:
- 在分支机构a创建并签出分支机构tmp(
)git branch tmp branch\u a&&git checkout tmp
git重置——软分支
git提交
如果有两个分支,则该提交必须具有所有差异:
有更改
需要更改
有更改
移动到需要更改
,然后执行以下操作:
git checkout -b deleteme has-changes # Create temporary branch to build commit on
git reset --soft needs-changes # Move diff into index
git commit # Create the diff patch commit
git checkout needs-changes # Switch to branch that needs changes
git cherry-pick deleteme # Apply the diff to the needs-changes
git branch -D deleteme # Delete the temporary branch
这一切都归结为一个git reset--soft branch_b,位于基于branch_a的临时分支之上,结果提交回branch_b 这是一个循序渐进的过程:
#Start out on the branch with the code we want
git checkout branch_a
#create tmp branch same as branch_a (so that we don't change our local branch_a state during the operation)
git branch tmp
#working directory has all the code that we want, on tmp branch
git checkout tmp
# Change the branch head to the branch we want to be on. All the delta
# between the current source code and branch_b is now staged for commit
git reset --soft branch_b
# Move away from tmp, so our commit will go directly to branch_b
git checkout branch_b
# Now you can examine the proposed commit
git status
# Add the delta we want to the branch
git commit
# Sanity check that the branches have the same content now (should return an empty line)
git diff branch_A..branch_b
# Remove tmp, we don't need it anymore
git branch -D tmp
您不需要一个普通的提交,甚至不需要在前面触碰分支。只要试着用gitk做它——当你在新的分支上进行实验时,不管怎样你都可以自由运行。我使用git 1.7.9.5更准确地工作:git branch tmp branchA&&git checkout tmp&&git reset--soft branchB&&git checkout branchB&&git branchB&&D tmp&&git commitbranch b名称有一个输入错误,应该是
to_branch\u b
这是git reset--soft
,git commit