b0rk, (edited )
@b0rk@jvns.ca avatar

let's imagine you're resolving this merge conflict (in screenshot).

You've forgotten which code comes from your current branch and which one comes from the "other" branch. How do you figure it out? Do you:

  1. remember what the "top" and "bottom" parts correspond to from past merge conflicts?
  2. remember what HEAD means?
  3. read the last line of the merge conflict?
  4. run something like git show main or git diff mybranch..main to see the diff?
  5. enable diff3
  6. something else?
b0rk,
@b0rk@jvns.ca avatar

a bunch of people have said that they feel embarrassed that they're still confused about which side of a merge conflict is which, even after many years using git.

I want to say that I have a hard time with it too (and I am uh EXTREMELY confident in my git skills at this point). Really appreciate everyone sharing their coping strategies for dealing with this not-very-clear UI.

willow_datawitch,

@b0rk Wrote myself a script that had clear labelling about where changes were coming from and what branch was being updated, and wrapped that around git for my merges. 😁

(Mostly I use a single branch, push to head approach and do mob programming now, but! When I was doing more merges, that’s what I did.)

ctietze,
@ctietze@mastodon.social avatar

@willow_datawitch @b0rk That sounds cool. Never thought of fiddling/extending the diff metadata lines. Is your script available somewhere?

thomasfuchs,
@thomasfuchs@hachyderm.io avatar

@b0rk Maybe… this is a sign that Git needs to change, not us :)

watters,
@watters@hachyderm.io avatar

@thomasfuchs @b0rk Perhaps, at a minimum, they might reconsider the "easy to learn" claim they make on the website…

inthehands,
@inthehands@hachyderm.io avatar

@thomasfuchs @b0rk
I just on Friday gave two of my classes a spiel to the effect of “it’s not you, it’s Git, it’s incredibly user-hostile and it’s not your fault.”

gsuberland,
@gsuberland@chaos.social avatar

@b0rk I wrote a thing that directly parses merge conflicts and I still can't remember which side is which.

ctietze,
@ctietze@mastodon.social avatar

@b0rk I can’t make heads or tails from this after 15 years. Something just doesn’t click. diff3 helps sometimes to infer which is which based on a common middle, but IMHO this is all awful

RichiH,
@RichiH@chaos.social avatar

@b0rk 2 & 3

zalasur,
@zalasur@mastodon.surazal.net avatar

@b0rk I'm not ashamed to admit it (though I probably should be) but I've literally resorted to cloning my branch in another directory to make sure my stuff makes it past the merge conflict if I'm not 100% sure.

ilmai,
@ilmai@hachyderm.io avatar

@b0rk 6. Use a GUI, I can’t trust myself not to shoot myself in the foot with git CLI

ShadSterling,

@b0rk my editor annotates the arrow lines with the branch names

b0rk,
@b0rk@jvns.ca avatar

@ShadSterling oh cool what a great feature

drwhitt,
@drwhitt@mastodon.social avatar

@b0rk Without considering other aspects, it seems that one always wants to take the second (>>>) change as this represents local changes. Why, with the exception of maybe another (recent) commit on the remote on the exact same line(s) of code would one want to discard their changes?

b0rk,
@b0rk@jvns.ca avatar

@drwhitt hmm i'm not sure what you mean -- this is a merge conflict, which means that the remote changed the exact same lines of code

joelanman,
@joelanman@hachyderm.io avatar

@b0rk I use a different UI that explains it better, I have no idea what this output means!

promovicz,
@promovicz@chaos.social avatar

@b0rk I remember what HEAD means, and avoid merges when possible by tending towards collaboration forms that coordinate well.

mjd,
@mjd@mathstodon.xyz avatar

@b0rk I proceed forward not really knowing which is which but it usually works out because I pretty much know what I want and I can figure out which pieces of each to stitch together to get there.

Not a great strategy. But maybe a useful data point.

mjd,
@mjd@mathstodon.xyz avatar

@b0rk I see this is pretty much what Simon Tatham said, except he seems less embarrassed.

simontatham,
@simontatham@hachyderm.io avatar

@mjd @b0rk I find the "don't let it distract you" strategy particularly valuable in cases where you're rebasing commits that aren't all working towards the same goal, e.g. repeated false starts + reverts + retries.

I find I get much better results in that situation if I reduce myself to a "just apply both changes at once" automaton than if I clutter my mind with trying to understand what's actually going on, because what's actually going on is confusing, whereas the current subtask is simple!

dachary,
@dachary@dacharycarey.social avatar

@b0rk If I don’t already know where the changes in the diff came from and am sure I know which one is correct, I open both branches elsewhere and confirm which one I want.

masukomi,
@masukomi@connectified.com avatar

@dachary @b0rk I remember that "HEAD" is almost always the stuff in my current working directory. But then there's the related "ours" and "theirs" which is ALWAYS confusing.

When dealing with non-trivial conflicts, I'll frequently use Kaleidoscope's graphical merge tool in 3-way mode. Then you see one file on the left, one on the right, and the center column is the resulting merged file. The 3 columns make it much easier to figure out the 2 starting contexts.

simontatham,
@simontatham@hachyderm.io avatar

@b0rk I think the best clue from that diff is the commit message from one side. Sometimes I can tell by knowing what one of the branches is about.

But also, I mostly don't find I need to know which is which. In fact I resist trying to figure it out, on the basis that it's a distraction. I just make a snippet of code in which both changes have been applied, and move on. In diff3 mode that's usually easy, and I make fewer mistakes that way than if I think harder about the big picture!

inthehands,
@inthehands@hachyderm.io avatar

@b0rk
I usually end up inspecting history with a GUI. (I like gitup.co for these sorts of task.)

This is a situation where GitHub fails extra hard, imo. It seems to me other version control systems somehow aren’t as confusing about how they show the conflict.

b0rk,
@b0rk@jvns.ca avatar

@inthehands huh i didn't know that github showed merge conflicts at all

acdha,
@acdha@code4lib.social avatar

@b0rk If I don’t remember the context, I often use a helper (via git mergetool). I used to use DiffMerge but now use Kaleidoscope, but the UI in VSC isn’t bad, either.

Edit to add: all of those tools tend to be nicer about resolving simple conflicts quickly so I can focus on the ones which require more thought.

nonnihil,

@b0rk I generally use the arrows on the assumption that "it's just like CVS or SVN, right?" but then second guess myself because I can never remember which commands reverse "mine" and "theirs" (is it just rebase?) and fall back to inspecting the code and trying to figure out what I meant.

b0rk,
@b0rk@jvns.ca avatar

@nonnihil how do you use the arrows? a bunch of people are saying this but I don't understand what information people are getting from the arrows

(specifically because when you merge vs rebase it flips the order completely)

joachim,
@joachim@drupal.community avatar

@b0rk In a rebase conflict, I copy the SHA from the CLI conflict message (which frustratingly has a '...' glued to it which means you can't double-click to select it...), then in a separate terminal window do 'git show SHA' to try to understand what the commit wants to change. I generally don't ever do merge conflicts -- if there is one, I rebase the branch, resolve conflicts in that, then merge.

joachim,
@joachim@drupal.community avatar

@b0rk There is a git config option to show a 3rd chunk, the common ancestor of both changes. But I'm not managing to find what it is on google, and looking in my .gitconfig files is not showing me anything useful!

joachim,
@joachim@drupal.community avatar

@b0rk Aha! I just saw another reply mention this -- it's diff3. (Though I have no idea how I've managed to get my system to show me this.)

b0rk,
@b0rk@jvns.ca avatar

@joachim should be somethling like git config --global merge.conflictstyle diff3

firefly,
@firefly@frogs.lgbt avatar

@b0rk the first I guess, since left/first argument is "before" and right/second argument is "after" in diff/patch kind of contexts

(I've also occasionally done a diff the "wrong way" at times and been very confused for a bit before realising, so I guess it's kind of in my subconscious at this point?)

b0rk,
@b0rk@jvns.ca avatar

@firefly do you usually use merge or rebase? what always trips me up is that the order of the merge conflict gets flipped in merge vs rebase

macmade,
@macmade@mastodon.social avatar

@b0rk IMHO it doesn’t really matter. Either you wrote the code and you should know the correct version, or you should look up the author and ask. Don’t merge something you don’t know about.

janl,
@janl@narrativ.es avatar

@macmade terrible advice ;D — You want

[merge]  
 conflictstyle = diff3  

and it’ll show you the base version, so you can make a correct mechanical resolution. :)

benjohn,
@benjohn@todon.nl avatar

@b0rk Also use a graphical three way, which helps a bit – p4.

benjohn,
@benjohn@todon.nl avatar

@b0rk This is a really great question.

I have git mergetool set up to use p4, but I never know which side is which. I always work it out based on the bits it is asking me to resolve and what I can remember of what I did and what other people have done (or I've done elsewhere).

But this doesn't feel easy!

benjohn,
@benjohn@todon.nl avatar

@b0rk I believe it flips depending on whether you're in a merge or a rebase? I'm sure I read that one time. Which hasn't helped me either way!

b0rk,
@b0rk@jvns.ca avatar

@benjohn it does flip! that's one of the main reasons it's hard I think.

Balise,
@Balise@hachyderm.io avatar

@b0rk
Sigh heavily and figure out manually what should actually be there

b0rk,
@b0rk@jvns.ca avatar

@Balise how do you figure it out manually?

rubbs,

@b0rk combo of the arrows and reading the branch/tag names. Especially because sometimes you are merging branches that aren't MAIN.

b0rk,
@b0rk@jvns.ca avatar

@rubbs ooh how do the arrows help you exactly?

LucasWerkmeister,
@LucasWerkmeister@wikis.world avatar

@b0rk I do whatever I can to get the conflict in “diff3” style instead (which might require some kind of --abort and repeating whatever I did)

I think this actually happened to me recently – I don’t remember why I didn’t get a diff3 diff, but I didn’t even try to understand it, I just reset and tried again with fixed config

mgattozzi,
@mgattozzi@hachyderm.io avatar

@LucasWerkmeister @b0rk in the future you can run git checkout --conflict diff3 the/file of you have this issue

b0rk,
@b0rk@jvns.ca avatar
jbwharris,

@b0rk this is one of the many reasons I use a GUI like Fork for Git.

bunnyhero,
czottmann,
@czottmann@norden.social avatar

@bunnyhero @jbwharris @b0rk Same here.

(Let's make this a UI client conga line, people.)

crmsnbleyd,
@crmsnbleyd@emacs.ch avatar

@b0rk the arrows, because I use diff every day (not git)

b0rk,
@b0rk@jvns.ca avatar

@crmsnbleyd interesting! how do the arrows help you figure out which code is which?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • GTA5RPClips
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • megavids
  • everett
  • tester
  • cisconetworking
  • Leos
  • cubers
  • modclub
  • ngwrru68w68
  • tacticalgear
  • anitta
  • provamag3
  • normalnudes
  • JUstTest
  • lostlight
  • All magazines