threads / discuss / 9260

Teach git-gui about merging around modified files?

Subject: Teach git-gui about merging around modified files?

## tl;dr

3 messages between Jul 27, 2007 and Jul 29, 2007.

replies: 2people: 2as markdown or json

Brian Downing· Jul 27, 2007, 17:03 UTC · lore

"git merge" will happily merge a change with modified files in the tree as long as the merge doesn't touch any of them. However, it appears "git gui" won't even try if there are modified files at all.

How hard would it be to fix this, or is this an intentional choice? I realize that commiting even untouched files before a merge is safer, but I'm tasked with migrating some CVS users to Git, and I'd prefer to be able to introduce the new Git workflow slowly.

(I'm happy enough with disallowing merges that actually touch modified files, so I'm not looking for any kind of in-working-directory merge like some others were. I'd just like the "git merge" behavior to work in git-gui.)

-bcd
Shawn O. Pearce· Jul 29, 2007, 07:36 UTC · re: Brian Downing · lore

Re: Teach git-gui about merging around modified files?

Brian Downing <bdowning@lavos.net> wrote:
> "git merge" will happily merge a change with modified files in the tree
> as long as the merge doesn't touch any of them.  However, it appears
> "git gui" won't even try if there are modified files at all.
Yes.  That is actually intentional...
 
> How hard would it be to fix this, or is this an intentional choice?
Its not hard to fix.  I just did it in a patch that would be:
 lib/merge.tcl |   12 +-----------
 1 files changed, 1 insertions(+), 11 deletions(-)

and we all know deleting more lines is good, but after I made the patch and started testing it I remembered exactly why I don't allow you to merge with modified files.

If you merge and get conflicts you cannot abort to your pre-merge state safely by just doing a `git reset --hard` (or git-gui's own builtin action that does the same) as you will toss your own not yet committed changes too. You really need to save those changes off first.

Show 8 quoted lines
> I realize that commiting even untouched files before a merge is safer,
> but I'm tasked with migrating some CVS users to Git, and I'd prefer
> to be able to introduce the new Git workflow slowly.
> 
> (I'm happy enough with disallowing merges that actually touch modified
> files, so I'm not looking for any kind of in-working-directory merge
> like some others were.  I'd just like the "git merge" behavior to work
> in git-gui.)

What do you do when the merge goes badly on the command line (lots of conflicts, but none to the files you have modified), and you want to get back to your pre-merge state? You can't, there's no state saved for git to reset back to.

Really what you want to do here is stash your local changes away, then do the merge, and after the merge is successfully completed apply the stash back onto your working tree. Because then if the merge goes badly you can `git reset --hard && git stash apply` to bring back your prior state.

So until git-gui plays along nicely with git-stash (can save and apply to it) I'm going to continue to disallow merging with uncommitted changes. Its just not a smart thing to be doing.

-- 
Shawn.
Shawn O. Pearce· Jul 29, 2007, 09:04 UTC · re: Shawn O. Pearce · lore

Re: Teach git-gui about merging around modified files?

"Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 12 quoted lines
> Brian Downing <bdowning@lavos.net> wrote:
> > "git merge" will happily merge a change with modified files in the tree
> > as long as the merge doesn't touch any of them.  However, it appears
> > "git gui" won't even try if there are modified files at all.
> 
> Yes.  That is actually intentional...
> 
> If you merge and get conflicts you cannot abort to your pre-merge
> state safely by just doing a `git reset --hard` (or git-gui's own
> builtin action that does the same) as you will toss your own not
> yet committed changes too.  You really need to save those changes
> off first.

I felt bad about my original response to this thread. Telling a user that their workflow is broken and should be changed is not very nice, and not user friendly.

So I just spent a couple of hours trying to teach git-gui to first save off your index and working directory, then run the merge, and during abort let you restore things even if they weren't committed.

During testing I learned that you can't merge if you have any staged but uncommitted changes. If you try git-merge-recursive just aborts and refuses to execute the merge, even if the file paths aren't in conflict and won't require a file level merge. The issue is the files are staged in the index and would commit as part of the merge commit, rather than staying out until after, so the merge driver is really doing the right thing here.

I'm still convinced that merging while you have uncommitted changes in the working directory is really bad. Its nearly impossible to recover from a conflict and get back to pre-merge state, and its also confusing to resolve conflicts because your unstaged but modified files are still showing in the status.

I'm going to shelve this work until post 0.8.0 and try to rework it using git-stash as part of git-gui 0.9.0. Ideally you should be able to stash your work before merging, and unstash after the merge is complete.

-- 
Shawn.

← back to recent threads