简体   繁体   中英

how to force manual merge with git instead of fast forward

I created a branch to solve an issue. In this branch I put many debug lines to identify the problem and I fixed it. So I have:

* (issue_b47)    Without the bug but with a lot of useless debug things
* (HEAD, master) With the bug

If I simply write this

git checkout master
git merge issu_b47

git will do a fast forward merge and I will then inherit all the debug things I don't want.

What I would like to do is to do a manual merge with my difftool . How to do it?

I think it easier to clearly see on the left panel of my difftool the issue_b47 branch and on the right panel the master branch. I can just decide to keep what is relevant to solve the issue, save the diff and finalize the merge. Is there any to do it so with git?

it sounds like you want the commit on the branch to be altered a bit. There's many ways to do that. Here are a couple common ones:

  1. Fix up the contents (get rid of the debug stuff), then git add -A; git commit --amend git add -A; git commit --amend on your branch, then merge as normal.

  2. git reset --soft HEAD~1 while on the branch, then git reset HEAD . , will pull everything back out and let you start the commit over again. You will have unstaged changes.

通过使用此命令,可以避免快进

git merge --no-ff branchname

From iss_b47 branch

git difftool HEAD~1 -- <file>

Presuming you have a suitable difftool configured you will get a side by side pane where you can move changes back and forth and then save the result. At that point you can git commit --amend and then git merge.

In the off change you happened to do git commit on just your debug changes and then did git commit --amend with the bug fix then you can use the reflog to extract the changes automatically.

Use --no-commit to force no commit, and --squash to create it's own commit rather than the same commit as (issue_b47)

git merge --no-commit --squash issu_b47

After this command, git will do the auto-merge and put the modified files in INDEX. You can find the modified files by git status .

At this stage you can use whatever tool to do your manual merge. After that git add + git commit to finish your merge. You will get a separate commit from the issue_b47 as it used to be in fast forward (which is normal because they have different changes in both commits)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM