How to force git into "merge conflict mode"?
git, merge
Solution
There are several options. The one that directly answers your question:
git merge --no-commit
will perform the auto-merge to the index and then stop, just as if manual conflict resolution were needed. Of course there will be no conflict markers and no changes "unstaged" / waiting for resolution, but you can modify the commit to look how you want before you commit.
The biggest problem with that, aside from "it's probably a mess to do", is that as far as git is concerned all changes in `bar` are now accounted for in `master`. Since you implied that you might want the remaining changes later, that's not good.
What you really want is something like
x --- O --- M <--(master)
\ /
A --- B <--(bar)
where `O` is the original branch point, `A` has the changes that you want now, and `B` has the changes you'll want later.
(Or, if you want to avoid the merge commit, you would want
x --- O --- A <--(master)
\
B <--(bar)
instead.)
How best to get to this depends on what you have now. If `bar` has just a single commit (or, in any event, if you're happy to end up with just one "commit to merge now" and one "commit to save for later"), and if there are no commits on `master` after `O`, you could do this:
Starting with
x --- O <--(master)
\
AB <--(bar)
you do
git checkout bar
git reset --mixed HEAD^
(assuming there's really just a single commit on `bar`; otherwise, replace `HEAD^` with something like the SHA1 value for commit `O` or a tag that you've put in place on commit `O`). Now you have
x --- O <--(master)(bar)
^HEAD
with all of the original changes from `bar` untracked in your working tree. Because all of the changes are in a single file, we need to use patch mode to selectively add changes
git add -p
# select the changes to merge
git commit
git stash
giving you
x --- O <--(master)
\
A <--(bar)
\ ^HEAD
B <--{stash}
So next
git checkout master
git merge bar
If you want a merge commit (preserving the topology in which your changes were made on `bar`) then pass `--no-ff` to the `merge` command. Otherwise, since we're assuming master hasn't diverged from `bar`, you'll just get a fast-forward leaving
x --- O --- A <--(master)(bar)
\ ^HEAD
B <--{stash}
(Conversely, if `master` had diverged yet you decide to linearlize history, you would rebase `A` onto `master` instead of merging...)
Then you can do something like
git branch --delete bar
git stash branch bar
to end at
x --- O --- A <--(master)
\
B <--(bar)
Problem
I have a file `foo` in branch `master`. It needs some work so I create branch `bar` where I do some work. Things look satisfactory so I am ready to merge back into `master`. Just one problem: I want to keep all of the changes I made in branch `bar` for future reference, but not all of the changes belong in the `master`, not right now anyway. But if I do the usual merge, git will not see any conflicts -- since file `foo` in `master` hasn't been edited -- and will just do the merge. Is there a way to force git to do this merge as if there were conflicts that I need to resolve? Or is there some other way to place only selected changes in `bar` into `master`?