5

Let's assume that there are two branches, master and slave, and they edit the same file and the same line. Initially, the contents of the file is

foo bar

then in the branch slave it is edited to become

foo bar baz

Now the user of branch slave formats the patch (git format-patch master) and sends it to the user of the branch master. In the same time, in the branch master the same file is edited and becomes

foo bar spam eggs

The patch cannot be applied, and master asks slave to merge and make a new patch. When master is merged into slave and the conflict is resolved, it's time to reformat the patch. The commit graph looks like this:

slave:               master:

foo bar baz spam eggs
    |             \
    |              \
    |                foo bar spam eggs
    |                    |
foo bar baz              |
       \                 |
        \                |
         +---------  foo bar

The latest commit (merge) on slave looks like:

@@@ -1,1 -1,1 +1,1 @@@
- foo bar baz
 -foo bar spam eggs
++foo bar baz spam eggs

However, if we now run git format-patch master, we still get exactly the same patch as before, which doesn't take merge and conflict resolution into account:

@@ -1 +1 @@
-foo bar
+foo bar baz

How do you format a patch which would apply against the latest master? I'd like to do it without rebase.

Update: git format rev1..rev2, where rev1 and rev2 are heads of the master and custom branches respectively, doesn't include changes related to conflict resolution. git-diff formats a valid patch, but omits commit messages.

sastanin
  • 40,473
  • 13
  • 103
  • 130

1 Answers1

1

Why are you using patches? You should be pushing and pulling between repos.

A merge is not something you can make a patch from. It will follow the first parent only. You can get what you want by using git diff and formatting for patch while specifying the 2 different commits to differentiate between.

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • I use patches, because this is what the upstream wants, and I am not in the control of workflow. I have to format patches which take conflict resolution into account, because I also publish my repo and cannot rebase. `git diff`, unfortunately, doesn't include commit messages. – sastanin Jun 18 '11 at 21:21
  • There's a way to make a merge have just one parent. A patch from that will get you the outcome you need. – Adam Dymitruk Jun 19 '11 at 18:00
  • A merge with just one parent? How is it possible? Isn't `git-merge` supposed to "join _two_ or more development histories together"? – sastanin Jun 19 '11 at 21:05
  • You can try --squash which will create a single commit of the merge, but then you lose the ability to traverse the merge back into the original branch. – Chris Nicola Jun 26 '11 at 00:00