Skip to content

Instantly share code, notes, and snippets.

@adamwespiser
Created December 21, 2015 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamwespiser/96f5c609ac74f2ce852a to your computer and use it in GitHub Desktop.
Save adamwespiser/96f5c609ac74f2ce852a to your computer and use it in GitHub Desktop.
git merge guide

###Overview: A quick exercise in using vimdiff to merge conflicted git files http://www.rosipov.com/blog/use-vimdiff-as-git-mergetool/ git {branch,checkout,merge}

###Set up

	git config --global merge.tool vimdiff
	git config --global merge.conflictstyle diff3
	git config --global mergetool.prompt false

####Create Merge Problem Make a new repo with a committed text file, then create a new branch. In the new branch, edit and commit changes to the text file. Switch back to the master branch, then attempt to merge

	mkdir zoo
	git init
	vi animals.txt #add a list of animals
	git add animals.txt
	git commit -m "initial commit"
	git branch newbranch # create a new branch
	git checkout newbranch # changes to a new branch
	vi animals.txt # make a change to the list of animals
	git add animals.txt
	git commit -m "update to animals.txt"`
	git checkout master
	git merge newbranch # this will cause a problem

####Fix Merge Problem The merge should have been aborted, as there are files in conflict. Fix the problem with git mergetool. There will be 4 files in the vim editor. LOCAL - the file from the current branch. BASE - the common ancestor. and REMOTE - the version of the file from 'new branch' MERGED - the file you are merging into your branch git mergetool

####Using vimdiff

  1. use Ctrl-w [jklh] or Ctrl-w [arrow key] to move to the MERGED file.
  2. To select a conflict, move your cursor over the highlighted text
  3. :diffg [RE,BA,LO] will get from [REMOTE,BASE,or LOCAL] Save the file with :wqa

####Problem Solved the following should now work

	git commit -m "fixed merge problem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment