Move

Harry immediately moves on to his next task, which is to restructure the tree a bit. He doesn’t want the top level of the repository to get too cluttered so he decides to move their vast number of source code files into a src subdirectory.

lottery harry$ mkdir src

lottery harry$ git mv lottery.c src

lottery harry$ git status -s
R  lottery.c -> src/lottery.c
?? a.out

lottery harry$ git commit -a -m "dir structure"
[master 0171af4] dir structure
 1 files changed, 0 insertions(+), 0 deletions(-)
 rename lottery.c => src/lottery.c (100%)

lottery harry$ git push
Counting objects: 3, done.
Writing objects: 100% (2/2), 223 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To http://server.futilisoft.com:8000/lottery
   05f316d..0171af4  master -> master

Having the number 7 as a constant in the code is so ugly it makes Sally’s hair hurt. She adds a #define to give it a more meaningful name.

lottery sally$ git diff
diff --git a/lottery.c b/lottery.c
index 8548299..cf21604 100644
--- a/lottery.c
+++ b/lottery.c
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#define LUCKY_NUMBER 7
+
 int calculate_result(int white_balls[5], int power_ball)
 {
     for (int i=0; i<5; i++)
@@ -50,7 +52,7 @@
         return -1;
     }
 
-    if (7 == power_ball)
+    if (LUCKY_NUMBER == power_ball)
     {
         result = result * 2;
     }

And immediately commits and pushes the change.

lottery sally$ git commit -a -m "use a #define for the lucky number"
[master f3988a0] use a #define for the lucky number
 1 files changed, 3 insertions(+), 1 deletions(-)

lottery sally$ git push
To http://server.futilisoft.com:8000/lottery
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'http://server.futilisoft.com:8000/lottery'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Hmmm. Sally needs to pull and merge before she can push her changes.

lottery sally$ git pull
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 8 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From http://server.futilisoft.com:8000/lottery
   b77378f..0171af4  master     -> origin/master
Auto-merging src/lottery.c
CONFLICT (content): Merge conflict in src/lottery.c
Automatic merge failed; fix conflicts and then commit the result.

Let’s see what the conflict is:

lottery sally$ git diff
diff --cc src/lottery.c
index cf21604,49c6688..0000000
--- a/src/lottery.c
+++ b/src/lottery.c
@@@ -45,7 -43,13 +45,17 @@@ int main(int argc, char** argv
  
    int result = calculate_result(white_balls, power_ball);
  
++<<<<<<< HEAD
 +  if (LUCKY_NUMBER == power_ball)
++=======
+   if (result < 0)
+   {
+       fprintf(stderr, "Invalid arguments\n");
+       return -1;
+   }
+ 
+   if (7 == power_ball)
++>>>>>>> 0171af4004103031d2ffb8d26fac0bcc9511060d
    {
        result = result * 2;
    }

She sees that the problem is easy to resolve.

lottery sally$ git diff
diff --cc src/lottery.c
index cf21604,49c6688..0000000
--- a/src/lottery.c
+++ b/src/lottery.c
@@@ -45,7 -43,13 +45,13 @@@ int main(int argc, char** argv
  
    int result = calculate_result(white_balls, power_ball);
  
+   if (result < 0)
+   {
+       fprintf(stderr, "Invalid arguments\n");
+       return -1;
+   }
+ 
 -  if (7 == power_ball)
 +  if (LUCKY_NUMBER == power_ball)
    {
        result = result * 2;
    }

And commits and pushes the change.

lottery sally$ git commit -a -m "merge"
[master 0e74df9] merge

lottery sally$ git push
Counting objects: 12, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (7/7), 602 bytes, done.
Total 7 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (7/7), done.
To http://server.futilisoft.com:8000/lottery
   0171af4..0e74df9  master -> master