add 9-conflicts
[gitjutsu.git] / 9-conflicts
blob63b65d5cca5c963f7e92eaa1b38284815edd723f
2 Whenever Git fails to apply a patch, it will put your tree in a state of conflict.
4 Up until now, I've advised you to deal with conflicts using the reset command, essentially running away from the problem.
6 At this point, I think you're ready to face them head-on.
9 During the conflict, your tree looks like this:
10 * All of the changes Git could safely make are in the staging area.
11 * All of the changes Git cannot safely make are marked in your local tree but not the staging area.
12 * All files with changes Git cannot safely make are marked as "unmerged".
14 To resolve the conflict, you must fix the unmerged files and add them to the index.
17 (TODO: make a better conflict than this next one. It's confusing.)
19 Conflicting areas are marked in your local tree like this:
21 [code]
22 <<<<<<< HEAD:server/trace.c
23     fprintf( stderr, " src_process=%04x", req->src_process );
24     fprintf( stderr, ", src_handle=%04x", req->src_handle );
25     fprintf( stderr, ", dst_process=%04x", req->dst_process );
26     fprintf( stderr, ", access=%08x", req->access );
27     fprintf( stderr, ", attributes=%08x", req->attributes );
28     fprintf( stderr, ", options=%08x", req->options );
29 =======
30     fprintf( stderr, " src_process=%p,", req->src_process );
31     fprintf( stderr, " src_handle=%p,", req->src_handle );
32     fprintf( stderr, " dst_process=%p,", req->dst_process );
33     fprintf( stderr, " access=%08x,", req->access );
34     fprintf( stderr, " inherit=%d,", req->inherit );
35     fprintf( stderr, " options=%d", req->options );
36 >>>>>>> 7b910f4... server: Use attributes instead of inherit flag in dup_handle request.:server/trace.c
37 [code]
39 The <<<<<<< line tells you which revision the first section is from.
40 The ======= line divides the two sections.
41 The >>>>>>> line identifies the second section.
43 In this case, I created the conflict by reverting a random patch in the Wine project.
45 The first section, HEAD, is from my tree as it was when I started the revert.
46 The second section is from my tree as it was just before the patch I'm reverting.
48 To make it more clear what's going on, here's a section from the patch I'm reverting:
50 [code]
51 @@ -846,8 +846,8 @@ static void dump_dup_handle_request( const struct dup_handle_request *req )
52      fprintf( stderr, " src_handle=%p,", req->src_handle );
53      fprintf( stderr, " dst_process=%p,", req->dst_process );
54      fprintf( stderr, " access=%08x,", req->access );
55 -    fprintf( stderr, " inherit=%d,", req->inherit );
56 -    fprintf( stderr, " options=%d", req->options );
57 +    fprintf( stderr, " attributes=%08x,", req->attributes );
58 +    fprintf( stderr, " options=%08x", req->options );
59  }
60 [/code]
62 To revert this change, Git must replace "attributes" with "inherit" and change the %08x in each of these lines to %d.
64 However, these lines do not exist in HEAD.
65 From the Git's marking of the conflict, I can see they look like this:
67 [code]
68     fprintf( stderr, ", attributes=%08x", req->attributes );
69     fprintf( stderr, ", options=%08x", req->options );
70 [/code]
72 Since that patch was applied, a comma was moved.
74 The solution is to take the first section (my current HEAD), and manually change it as Git would if it could.
75 As a human, I know the difference in punctuation is unimportant and can be ignored.
76 The conflicting section now looks like this:
78 [code]
79     fprintf( stderr, " src_process=%04x", req->src_process );
80     fprintf( stderr, ", src_handle=%04x", req->src_handle );
81     fprintf( stderr, ", dst_process=%04x", req->dst_process );
82     fprintf( stderr, ", access=%08x", req->access );
83     fprintf( stderr, ", inherit=%d", req->inherit );
84     fprintf( stderr, ", options=%d", req->options );
85 [/code]
87 Now, git diff shows me this odd-looking thing:
89 [code]
90 @@@ -1281,12 -842,12 +1281,12 @@@ static void dump_set_handle_info_reply
91   
92   static void dump_dup_handle_request( const struct dup_handle_request *req )
93   {
94  -    fprintf( stderr, " src_process=%p,", req->src_process );
95  -    fprintf( stderr, " src_handle=%p,", req->src_handle );
96  -    fprintf( stderr, " dst_process=%p,", req->dst_process );
97  -    fprintf( stderr, " access=%08x,", req->access );
98  -    fprintf( stderr, " inherit=%d,", req->inherit );
99  -    fprintf( stderr, " options=%d", req->options );
100  +    fprintf( stderr, " src_process=%04x", req->src_process );
101  +    fprintf( stderr, ", src_handle=%04x", req->src_handle );
102  +    fprintf( stderr, ", dst_process=%04x", req->dst_process );
103  +    fprintf( stderr, ", access=%08x", req->access );
104 -     fprintf( stderr, ", attributes=%08x", req->attributes );
105 -     fprintf( stderr, ", options=%08x", req->options );
106 ++    fprintf( stderr, ", inherit=%d", req->inherit );
107 ++    fprintf( stderr, ", options=%d", req->options );
108   }
109 [/code]
111 That is a 3-way diff.
113 It's Git's way of showing two patches at once.
114 Instead of a single column of spaces, pluses, and minuses, there are two columns.
116 The first column tells how the working tree differs from the first revision, the current HEAD.
117 The lines that have minuses in the first column are in HEAD but not in the working tree.
118 The lines that have pluses in the first column are in the working tree but not HEAD.
120 Similarly, the second column tells how the working tree differs from the revision before the reverted patch.
122 (TODO: I really need to find a better example. This is ugly and confusing.)
124 Once the conflict in each file is resolved, let git know by updating the index:
126 [code]
127 $ git add server/trace.c
128 [/code]
130 Once all conflicts are resolved, run
131 [code]
132 git commit
133 [/code]
135 If you are doing a rebase, you'll need to run
136 [code]
137 git rebase --continue
138 [/code]
140 [TODO: does "git commit" work properly here during a rebase?]
143 [TODO: are merges different in any important way?]