3

1. Abstract

My ultimate goal is to bring some Client's changes done on a Client's branch in the linux-kernel repo to another linux-kernel repository, given the fact that both have a common base tag (e.g. v4.2, from which the Client's branch has been initially created).

For that I am trying to create a stack of patches representing the diff between the base and the head of the Client's branch. During this first step, I am using git format-patch. The second step is applying those patches in the second repo using git am.

git diff and GNU diff are not of interest to me, as I don't want to lose the commit metadata (author, message, etc).

2. Demo setup

I have created a simple git commit flow to exemplify the problem. The following graphs depict the branch setup of this demo repo:

  1. Gitg graph - commit time order: enter image description here

  2. Gitg graph - topological order: enter image description here

  3. Gitk graph:
    enter image description here

  4. git log --oneline --graph --decorate: enter image description here

3. Steps to reproduce the issue

  • $ git status
    On branch master Your branch is up-to-date with origin/master. nothing to commit, working directory clean.

  • $ git format-patch BASE
    0001-commit-2-br1.patch

  • $ git checkout BASE
    HEAD is now at 65772fd... commit 3-master

  • $ git apply 0001-commit-2-br1.patch
    error: patch failed: file:1 error: file: patch does not apply

4. Additional info & Questions

  • git diff BASE f316460 > my.patch works! However, as stated in the Abstract, this is not a solution for me.

  • I believe git format-patch is just not smart enough in the multiple branch setup. Have anyone run into the same problems?

  • Are there any methods to achieve the same goal without git format-patch?

Eugeniu Rosca
  • 4,947
  • 12
  • 39
  • You have to read documentation on `git rebase` command, in particular on `git rebase --onto`. Do not reinvent a wheel, please. – 0andriy Dec 19 '15 at 15:30
  • @Andy Shevchenko: Thanks, I've managed to simply rebase the new local branch to the Client's remote branch. However, the `git format-patch` problem is still valid, from my point of view. – Eugeniu Rosca Dec 20 '15 at 10:50
  • You did apparently something difficult to understand. You have a merge commit, which is unusual to Git (yes, merge commits are exceptions and handled in a specific way). I'm pretty sure that `git format-patch` created something different to what you have in `git diff`. You may try to run `patch -p1 < 0001-commit-2-br1.patch` and see what is wrong. – 0andriy Dec 20 '15 at 13:28
  • @AndyShevchenko: To me the commit diagram looks pretty simple and common. `git am`, `git apply` and GNU `patch` *all* fail. `git format-patch` fails even when considering as `BASE` the first commit (I would have chosen that case, if I knew it before starting this thread). – Eugeniu Rosca Dec 20 '15 at 14:39
  • **You may try to run `patch -p1 < 0001-commit-2-br1.patch` and see WHAT WENT WRONG.** – 0andriy Dec 22 '15 at 13:24
  • @AndyShevchenko: I appreciate your intention to help, but non-bold fonts are fine enough to communicate your ideas to people :). If no git guru makes his appearance in this thread in the nearest future, I am going to just post the conclusions of my analysis in a separate answer. – Eugeniu Rosca Dec 22 '15 at 16:21

0 Answers0