在git中创建补丁会带来一些麻烦 [英] Creating a patch in git gives some headaches
问题描述
现在我想创建相对于最近上游主提交只有相关更改的修补程序。相关更改全部在合并提交中,我将原始错误修复分支合并到了较新的错误修复分支中。
现在,当我运行
git format-patch master
其中主指向我分支较新的修复分支的提交,它创建了多个补丁文件,其中包含来自原始修复分支的提交。我只需要简单的bug修复更改,就像我运行的那样获得的更改
git diff master
详细说明:问题不在于我得到多个补丁文件。问题是这些补丁包含了当前分支中没有包含的各种调试更改等。
我应该如何创建合法补丁?
清理你的工作的正常方式是使用交互式重新分页,通过 git rebase -i
另一种选择是,如果你想最终完成一次代表你所有工作的提交,那就是用来进行压缩合并。git merge - 考虑到你目前的情况,如果你想保留合并提交的内容并创建一个新的提交,你可以尝试以下(假设您已签出到您的功能分支,并且它指向您创建的合并提交)
git reset --soft master
git commit
这会给你一个提交你的改变,和 format-patch
将按预期工作。
I have cloned an upstream repository, started a bug-fixing branch on it, and spend quite a lot of time fiddling with it. Since I spent a lot of time with the branch and made all kinds of debugging and trivial changes to it, I branched a new branch from the more recent upstream master, and to that branch, merged the actual, finalized bug-fixing changes from my original bug-fixing branch, leaving out the cruft.
Now I'd like to create patch that has only the relevant changes relative to the recent upstream master commit. The relevant changes are all in the merge commit where I merged the original bug fixing branch to the newer one.
Now, when I run
git format-patch master
where master points to the commit from which I branched the newer fix branch, it creates multiple patch files with commits from the original bug fixing branch. I want just the single, concise bug-fixing changes, like those I get if I run
git diff master
To elaborate: the problem is not the fact that I get multiple patch files. The problem is that those patches contain all kinds of debug changes etc. that aren't included in the current branch.
What should I do to create a legit patch?
git format-patch
will create patches for all commits in the history you give it.
The normal git way to clean up your unpushed work is to use interactive rebase, via git rebase -i
Another option, if you wanted to end up with a single commit representing all of your work would be to do a squash merge with git merge --squash
.
Given your current situation, if you want to preserve the contents of the merge commit and create a single new commit you could try the following (presuming you are checked out to your feature branch, and that it is pointing to the merge commit you created)
git reset --soft master
git commit
This would give you a single commit with your changes, and format-patch
would work as expected.
这篇关于在git中创建补丁会带来一些麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!