Creating a patch in git gives some headaches

我是研究僧i 提交于 2019-12-13 05:15:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26395319/creating-a-patch-in-git-gives-some-headaches

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!