0

So I do a:

git merge --no-ff --no-commit source\branch

Great, merge is inprogress (I have a MERGE_HEAD in the .git folder)... But it staged some files...

I want to UNSTAGE those files, but NOT cancel the merge....

I can do this via theVisual Studio IDE.....

But a

git reset

seems to cancel the merge [MERGE_HEAD goes away]....

So How to un-stage, but leave it as a merge in progress so I can make the actual chages I wan, but get it recorded as a merge (multi-parent)

**NOTE: This question is distinct from all others I have seen because of the need to preserve an existing MEGE_HEAD and associated state...

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
David V. Corbin
  • 344
  • 1
  • 10
  • It's clear that you don't want any files staged (yet). But do you want your worktree updated from the merge with those changes pending (ready to be staged), or do you not want those either? – TTT Mar 27 '23 at 19:11
  • @TTT - It does not matter if the worktree is updated, I will be copying in a complete set of files overwriting what is there [either unchanged, or impacted] – David V. Corbin Mar 27 '23 at 22:03
  • In that case you may like the idea of using `-s ours` as in [jthill's answer](https://stackoverflow.com/a/75859242/184546). That will merge in the commit IDs without any of the actual changes, typically for historical reasons and/or so future changes from that branches can be merged in independently without the older (out-of-date) changes. – TTT Mar 27 '23 at 22:42

2 Answers2

2

Try git reset . or git reset <path1> <path2> ...

Or use git restore :

git restore --staged .

The versions with a pathspec reset index entries for the specified paths, but do not affect the active commit.

If you do not specify a path, on the other hand, git reset will change the state of the active commit or current branch, and will apparently discard information about an ongoing merge (I can reproduce the same behavior on a test repo).

LeGEC
  • 46,477
  • 5
  • 57
  • 104
1

To do it in advance, tell Git to do no automerging at all:

git merge --no-commit --no-ff -s ours sourcebranch

To do it retroactively, there's a core command that undoes the automerging (by just stomping on it with the -s ours result):

git read-tree --reset @
jthill
  • 55,082
  • 5
  • 77
  • 137
  • A few things about `-s ours` here: 1.) It's not clear if this is what OP wants, since it also won't update the worktree. 2.) The `read-tree` command does unstage and leave the worktree intact, but obviously this is a different state than the the `-s ours` merge will do, so the two aren't "either or". 3.) I assume that when using `-s ours` the `--no-ff` is redundant, otherwise we'd all be crying. :D – TTT Mar 27 '23 at 19:03
  • Thank's will try in the morning.... – David V. Corbin Mar 27 '23 at 22:04
  • OP, @TTT's criticisms of my answer are on target, if what you want to do is have the index reflect every change so you have to approve them all [this question](https://stackoverflow.com/q/41803083/1290731) looks like a likely duplicate, I probably should have made my answer a comment because I'm not sure exactly what you're after, so it's a bit scattershot. – jthill Mar 27 '23 at 23:58