threads / discuss / 15931

commiting while the current version is in conflict

Subject: commiting while the current version is in conflict

## tl;dr

10 messages between Oct 16, 2008 and Oct 17, 2008.

replies: 9people: 5as markdown or json

Richard Hartmann· Oct 16, 2008, 22:10 UTC · lore
Hi all,

I fooled around with git a liitle bit and noticed something rather strange. I merged two branches, creating a conflict on purpose. When I then did a

 git commit -a

all changes were submitted. Of course, I now have a file with the conflict markers inlined in my repository. Not a good thing, imo. Is there a way to make git block all conflicting versions?

Also, I would be interested in the design decissions behind the current behaviour. Any pointers?

Thanks, Richard

Miklos Vajna· Oct 16, 2008, 22:48 UTC · re: Richard Hartmann · lore

Re: commiting while the current version is in conflict

On Fri, Oct 17, 2008 at 12:10:55AM +0200, Richard Hartmann <richih.mailinglist@gmail.com> wrote:
> all changes were submitted. Of course, I now have a
> file with the conflict markers inlined in my repository. Not
> a good thing, imo. Is there a way to make git block all
> conflicting versions?
Write a pre-commit hook that checks for conflict markers?
> Also, I would be interested in the design decissions
> behind the current behaviour. Any pointers?

Not sure, but in general blocking conflict markers by default would be a bad idea IMHO, several markup language (asciidoc, for example) makes use of the >>>, === and such character sequences.

Shawn O. Pearce· Oct 16, 2008, 23:00 UTC · re: Miklos Vajna · lore

Re: commiting while the current version is in conflict

Miklos Vajna <vmiklos@frugalware.org> wrote:
Show 7 quoted lines
> On Fri, Oct 17, 2008 at 12:10:55AM +0200, Richard Hartmann <richih.mailinglist@gmail.com> wrote:
> > all changes were submitted. Of course, I now have a
> > file with the conflict markers inlined in my repository. Not
> > a good thing, imo. Is there a way to make git block all
> > conflicting versions?
> 
> Write a pre-commit hook that checks for conflict markers?
The sample pre-commit hook checks for these.  Its really hande to
have enabled.
 
Show 6 quoted lines
> > Also, I would be interested in the design decissions
> > behind the current behaviour. Any pointers?
> 
> Not sure, but in general blocking conflict markers by default would be a
> bad idea IMHO, several markup language (asciidoc, for example) makes use
> of the >>>, === and such character sequences.
Not only that, but "git commit -a" did exactly what you asked it to do:
	git add -u
	git commit
and git add -u is basically a faster way to do something like this pseudo-shell:
	for path in $(git status | grep modified:)
	do
		git add $path
	done

and merge conflicts are "resolved" by you running "git add $path" after you have finished fixing that path.

Moral of the story is, don't use "git commit -a". Use only "git commit" and stage files individually. That way when you are in a merge conflict you won't be in the habit of writing "git commit -a" and staging everything from the working tree implicitly.

-- 
Shawn.
Richard Hartmann· Oct 16, 2008, 23:26 UTC · re: Shawn O. Pearce · lore

Re: commiting while the current version is in conflict

On Fri, Oct 17, 2008 at 01:00, Shawn O. Pearce <spearce@spearce.org> wrote:
> The sample pre-commit hook checks for these.  Its really hande to
> have enabled.
Thanks.
> and merge conflicts are "resolved" by you running "git add $path"
> after you have finished fixing that path.

True, git add is an implicit resolving, I did not think about it this way. Personally, I think that git should break at this point, but that's just me.

The obvious fix would be a pre-add hook. Does anyone else think this would make sense?

Judging from the code in the pre-commit script, git does not keep conflict information in its metadata cache, but tries to guess conflicts from the file's contents/ This seems to be a strange thing to do, imo. What's the reason for this?

Richard
Avery Pennarun· Oct 17, 2008, 01:16 UTC · re: Richard Hartmann · lore

Re: commiting while the current version is in conflict

On Thu, Oct 16, 2008 at 7:26 PM, Richard Hartmann <richih.mailinglist@gmail.com> wrote:

Show 10 quoted lines
> On Fri, Oct 17, 2008 at 01:00, Shawn O. Pearce <spearce@spearce.org> wrote:
>> and merge conflicts are "resolved" by you running "git add $path"
>> after you have finished fixing that path.
>
> True, git add is an implicit resolving, I did not think about it this way.
> Personally, I think that git should break at this point, but that's
> just me.
>
> The obvious fix would be a pre-add hook. Does anyone else think
> this would make sense?

That would be awesome. I've frequently been bitten by accidentally running "git add" on a file that I *think* I've resolved the conflicts on, but it turns out I missed a commit marker or two. And then the handy conflict-style "git diff" is no longer available, among other things. If "git add" could prevent me from adding the file at all, it might save me some trouble.

On the other hand, an even better alternative would be to have a way to "unadd" a file and bring back the conflict information, but I don't know how that would really work.

Have fun,
Avery
Richard Hartmann· Oct 16, 2008, 23:07 UTC · re: Miklos Vajna · lore

Re: commiting while the current version is in conflict

On Fri, Oct 17, 2008 at 00:48, Miklos Vajna <vmiklos@frugalware.org> wrote:
> Not sure, but in general blocking conflict markers by default would be a
> bad idea IMHO, several markup language (asciidoc, for example) makes use
> of the >>>, === and such character sequences.
Doesn't git keep metadata about conflicts, as well?
Richard
Shawn O. Pearce· Oct 16, 2008, 23:23 UTC · re: Richard Hartmann · lore

Re: commiting while the current version is in conflict

Richard Hartmann <richih.mailinglist@gmail.com> wrote:
Show 7 quoted lines
> On Fri, Oct 17, 2008 at 00:48, Miklos Vajna <vmiklos@frugalware.org> wrote:
> 
> > Not sure, but in general blocking conflict markers by default would be a
> > bad idea IMHO, several markup language (asciidoc, for example) makes use
> > of the >>>, === and such character sequences.
> 
> Doesn't git keep metadata about conflicts, as well?

Yes, in the index. But it erases it when you stage the file with "git add".

Go look at my prior message about how "git commit -a" is staging the files prior to commit. That makes git commit think everything has been resolved, because you've told git, everything is resolved.

-- 
Shawn.
Richard Hartmann· Oct 16, 2008, 23:31 UTC · re: Shawn O. Pearce · lore

Re: commiting while the current version is in conflict

On Fri, Oct 17, 2008 at 01:23, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 6 quoted lines
> Yes, in the index.  But it erases it when you stage the file with
> "git add".
>
> Go look at my prior message about how "git commit -a" is staging
> the files prior to commit.  That makes git commit think everything
> has been resolved, because you've told git, everything is resolved.

This makes a good part of my latest email obsolete. Asynchronous communication ftw ;)

Richard
Jakub Narebski· Oct 16, 2008, 23:42 UTC · re: Richard Hartmann · lore

Re: commiting while the current version is in conflict

"Richard Hartmann" <richih.mailinglist@gmail.com> writes:
Show 10 quoted lines
> I fooled around with git a liitle bit and noticed something
> rather strange. I merged two branches, creating a conflict
> on purpose. When I then did a
> 
>  git commit -a
> 
> all changes were submitted. Of course, I now have a
> file with the conflict markers inlined in my repository. Not
> a good thing, imo. Is there a way to make git block all
> conflicting versions?
The default pre-commit hook shipped with git includes this check.  
All you have to do is enable it: it has to be named 'pre-commit' and
it has to be exacutable.  In older git version you would do:
  $ chmod a+x .git/hooks/pre-commit
while in never versions it would be
  $ mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
 
> Also, I would be interested in the design decissions
> behind the current behaviour. Any pointers?
It is a git policy that it ships with all hooks disabled.

P.S. You can always bypass pre-commit hook (for example if comitting AsciiDoc files, which may include something that looks like conflict markers, or if you are committing test which includes conflicted file as one of test vectors), by using `--no-verify' option to git-commit.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Richard Hartmann· Oct 17, 2008, 07:25 UTC · re: Jakub Narebski · lore

Re: commiting while the current version is in conflict

On Fri, Oct 17, 2008 at 01:42, Jakub Narebski <jnareb@gmail.com> wrote:
> [a lot of detailed information]

Thanks! 'Unfortunately', I figured all this out by myself, in the meantime, but I really appreciate that you took the time to explain all this .

Thanks! Richard

PS: Well, I lie, I did not figure out the mv $1.sample $1 bit
as my git version still uses the old format.

← back to recent threads