4

N.B. I’m using Windows 10, but I do have access to a Ubuntu 20 VM server (no desktop GUI). I installed mercurial by installing tortoisehg which also “courtesy” installs KDiff3 for merging.

The git repo I’m using is being hosted in github. I’m using the Ubuntu server to edit the working directory files using various Unix text editors.

I haven’t used git much. I’m much more proficient in mercurial. Let’s say I have a branch called beta that was started from master. I found a typo in dude.htm that has been around since the repo was started. To fix it in both branches I do the following:

hg update master
# Open up my favorite GUI text editor and fix the typo.  Save file
hg commit -m "Fix typo in dude"

Here I might build my project via continuous integration and verify the typo has been fixed. Now I want to merge this into beta

hg update beta
hg merge master
# here TortiseHg will ask me how I want to handle file conflicts 
# and bring up KDiff3 to assist me with merging
hg commit -m "merge master > beta"

This has been a solid process that’s worked for years. I’d like to be able to do the same thing with this git repo. I’d like to be able to edit the files of this git repo on my Windows box, but I’m somewhat leery about doing so because I always get into issues revolving around end of line (and other) symbols.

How can I perform a git merge like the hg merge I described above? Is there a GUI like KDiff3 that will work from an Ubuntu command line git merge command?

WhiskerBiscuit
  • 4,795
  • 8
  • 62
  • 100
  • 1
    Git's merge tool configuration is different (and feels to me a bit more primitive than) Mercurial's, but you definitely can use kdiff3 to handle merge conflicts in Git, using `git merge` followed by `git mergetool`. I don't actually *use* kdiff3 though (nor tortoise-anything) so I don't have specific settings for you. – torek Aug 21 '20 at 19:22
  • Is it specifically the 3-way visual merge that you are looking for? – StayOnTarget Aug 24 '20 at 11:51

1 Answers1

0

As far as git commands go : from the cli, you would run

git checkout master
# fix the typo ...

# one change from Mercurial : in git you have to explicitly add the files
# in the staging area (also called 'index') before committing :
git add path/to/dude.htm
                                   # where you explicitly add the files in 
git commit -m "Fix typo in dude"   # or just 'git commit', then type the commit
                                   # message in the editor that opens
  • git add -u : add all files that are already tracked in the staging area
    you can review the content before committing
  • git add -A : add all files from disk in the

Run CI, test the fix ...

To merge into beta :

git checkout beta
git merge -m "merge master > beta" master

# if the merge triggers merge conflict :
git status        # will highlight the conflicting files

git mergetool     # will open your mergetool of choice (eg: kdiff3), once for each 
                  # conflicting file

# once you have fixed the conflicts, run :
git commit
LeGEC
  • 46,477
  • 5
  • 57
  • 104