git merge common ancestors

rm -rf git-merge
mkdir git-merge
cd git-merge
git init
echo "public class A {" > file.txt
git add file.txt
git commit -m "master: initial create" file.txt
git checkout -b "feature-branch"
echo " public void myMethod(String master, String feature1) {" >> file.txt
git commit -a -m "feature-branch: updated 1x file.txt"
git checkout master
echo " public void myMethod(String master, String master2) {" >> file.txt
git commit -a -m "master: updated 1x file.txt"
git checkout feature-branch
git config --global merge.conflictstyle diff3
git rebase master
cat file.txt
public class A {
<<<<<<< 67ab579b2ad9eee0ddab24552486fb0ad4856180
 public void myMethod(String master, String master2) {
||||||| merged common ancestors #empty since myMethod were added/appended by later commits
=======
 public void myMethod(String master, String feature1) {
>>>>>>> feature-branch: updated 1x file.txt
mkdir git-merge
cd git-merge
git init
echo "public class A {" > file.txt
echo " public void myMethod(String master) {" >> file.txt
git add file.txt
git commit -m "master: initial create" file.txt
git checkout -b "feature-branch"
echo "public class A {" > file.txt
echo " public void myMethod(String master, String feature1) {" >> file.txt
git commit -a -m "feature-branch: updated 1x file.txt"
git checkout master
echo "public class A {" > file.txt
echo " public void myMethod(String master, String master2) {" >> file.txt
git commit -a -m "master: updated 1x file.txt"
git checkout feature-branch
git config --global merge.conflictstyle diff3
git merge master
cat file.txt
public class A {
<<<<<<< HEAD
 public void myMethod(String master, String feature1) {
||||||| merged common ancestors
 public void myMethod(String master) { # ancestor line comes from master initial commits - parent for both of later commits
=======
 public void myMethod(String master, String master2) {
>>>>>>> master
NOTE: for resolving conflict find the easier change vs ancestor and apply it to the other branch that have more complicated changes, eventually delete all <<< === >>>
the same would be for rebasing:
git rebase master
cat file.txt
public class A {
<<<<<<< 0eb56663659a69ae3e04323520c9c90d8405ed21
 public void myMethod(String master, String master2) {
||||||| merged common ancestors
 public void myMethod(String master) {
=======
 public void myMethod(String master, String feature1) {
>>>>>>> feature-branch: updated 1x file.txt


$ git diff HEAD..master
diff --git a/file.txt b/file.txt
index 3e27eb0..fd94a49 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 public class A {
- public void myMethod(String master, String feature1) {
+ public void myMethod(String master, String master2) {

$ git diff master..HEAD
diff --git a/file.txt b/file.txt
index fd94a49..3e27eb0 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 public class A {
- public void myMethod(String master, String master2) {
+ public void myMethod(String master, String feature1) {

$ git diff HEAD

$ git diff master
diff --git a/file.txt b/file.txt
index fd94a49..3e27eb0 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 public class A {
- public void myMethod(String master, String master2) {
+ public void myMethod(String master, String feature1) {

$ git diff HEAD~1..HEAD
diff --git a/file.txt b/file.txt
index ab74287..3e27eb0 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 public class A {
- public void myMethod(String master) {
+ public void myMethod(String master, String feature1) {

$ git diff master~1..master
diff --git a/file.txt b/file.txt
index ab74287..fd94a49 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
 public class A {
- public void myMethod(String master) {
+ public void myMethod(String master, String master2) {

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s