Skip to content

Git merge

Sébastien LUCAS edited this page Aug 27, 2014 · 11 revisions

How to merge files that has been splitted

http://stackoverflow.com/questions/2953808/merge-changes-when-a-file-on-a-branch-has-split-into-two-files-on-the-master

Merge technics

Manual merge

When a file is being splitted for example, the automatic merge is very complicated to undesrtand One technics is :

  • Use the last version of the file from the branch where we want to merge something
  • use git diff commit commmit afile to get a diff of all changes in the problematic file
  • in the diff use context to identify the insertion points
  • copy and paste the code modification one by one

Show the changes separately

http://stackoverflow.com/questions/101752/aborting-a-merge-in-git#107860

# common base:
git show :1:_widget.html.erb

# 'ours'
git show :2:_widget.html.erb

# 'theirs'
git show :3:_widget.html.erb

We can use git diff

git diff :2:file.txt :3:file.txt

Use 3 style

http://stackoverflow.com/questions/16990657/git-merge-diff3-style-need-explanation Indicate HEAD / the merged branch / and the common base

find the common ancestor

git merge-base planningv6-mergemaster coachingcook
# output a commit like d127cab188e9de25546fe5387e497ef42b16756a
#Then we show what is this ancestor commit
git log | grep -a2 -b2 d127cab188e9de25546fe5387e497ef42b16756a 
11130-    shopping list - checkboxes added
11167-
11168:commit d127cab188e9de25546fe5387e497ef42b16756a
11216-Author: Sebastien Lucas <sebastien@kiwings.com>
11264-Date:   Tue Jul 29 13:19:43 2014 +0000

WIKI by Sébastien Lucas CEO & Funder or Bricks

Clone this wiki locally