Conflicts

Figure 406. Conflicting changes Slide presentation Create comment in forum
User A: Print.java User B: Print.java
// Driver class
public class Print {
  public static void
    main(String[] args) {
      System.out.println
        (Math.add(2, 3));
  }
}
/**
 * Application entry point
 */
public class Print {
  public static void
    main(String[] args) {
      System.out.println
        (Math.add(2, 3));
  }
}

Figure 407. Commit schedule Slide presentation Create comment in forum
User A User B
Edit: ... Driver class ... -
git commit, git push -
- edit: ... Application entry point ...
- git commit
- git push: Fail!

Figure 408. User B: git push fails Slide presentation Create comment in forum
>git push ...
To https://gitlab.mi.hdm-stuttgart.de/goik/gitintro.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to
        'https://gitlab.mi.hdm-stuttgart.de/goik/gitintro.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.

Figure 409. User B: git pull fails as well Slide presentation Create comment in forum
>git pull 
...
From https://gitlab.mi.hdm-stuttgart.de/goik/gitintro
   b003a82..dbbedb0  master     -> origin/master
Auto-merging Print.java
CONFLICT (content): Merge conflict in Print.java
Automatic merge failed; fix conflicts and then commit the result.

Figure 410. Merge conflict details Slide presentation Create comment in forum
>git diff Print.java
diff --cc Print.java
index fc36ae6,7b27edf..0000000
--- a/Print.java
+++ b/Print.java
@@@ -1,6 -1,4 +1,10 @@@
++<<<<<<< HEAD
 +/**                        
 + * Application entry point
 + */
++=======
+ // Driver class 
++>>>>>>> dbbedb0fc29d77beeaaada37f2538d78f82bac93
public class Print {
  public static void
    main(String[] args) {
      System.out.println
        (Math.add(2, 3));
  }
}

Changes of user A.

Own changes of user B.


Figure 411. Struggling for resolution Slide presentation Create comment in forum
Struggling for resolution

Figure 412. Merging Print.java manually Slide presentation Create comment in forum
<<<<<<< HEAD
/**
 * Application entry point 
 */
=======
// Driver class 
>>>>>>> 10cf21c ... 759462c
public class Print {
  public static void
    main(String[] args) {
      System.out.println
        (Math.add(2, 3));
  }
}
/**
 * Driver class, application entry point 
 */
public class Print {
  public static void
    main(String[] args) {
      System.out.println
        (Math.add(2, 3));
  }
}

Figure 413. Commit and push merge Slide presentation Create comment in forum
>git add Print.java 

>git commit --message "Merging changes" 
[master 173487a] Merging changes

>git push
...
To https://gitlab.mi.hdm-stuttgart.de/goik/gitintro.git
   10cf21c..173487a  master -> master

exercise No. 125

git distributed, DIY Create comment in forum

Q:

Find a partner sitting next to you and repeat the current examples from the section called “Shared development with centralized remote.” and most importantly the section called “Conflicts”.

Do not hesitate creating a (source code!) conflict. You'll learn how to resolve it anyway.