Ads by Google

Thursday, January 1, 2009

Applying the same patch again and again

I sync up my org-mode code using git by issuing git pull. And I keep getting the same error every time the one file I edit is modified.

$ git pull
remote: Counting objects: 98, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 85 (delta 57), reused 82 (delta 54)
Unpacking objects: 100% (85/85), done.
From git://
8915859..cd92610 master -> origin/master
Updating 8915859..cd92610
error: Entry 'Makefile' not uptodate. Cannot merge.

That's because the Makefile has been edited to point to the correct Emacs binary path and other customisations. So I had to rename the Makefile and then redo the command.

$ mv Makefile m
$ git pull
Updating 8915859..cd92610
Fast forward
ChangeLog | 6 +
Makefile | 2 +
ORGWEBPAGE/ | 140 ++++++++++++++++-
doc/ChangeLog | 12 ++
doc/org.texi | 170 +++++++++++++++-----
lisp/ChangeLog | 51 ++++++
lisp/org-exp.el | 291 +++++++++++++++++++++--------
lisp/org-export-latex.el | 37 +++--
lisp/org-footnote.el | 391+++++++++++++++++++++++++++++++
lisp/org.el | 81 ++++++++--
10 files changed, 1042 insertions(+), 139 deletions(-)
create mode 100644 lisp/org-footnote.el

And then edit the Makefile to re-apply the changes again. Specifically the diff lines highlighted is what I have to change everytime.

$ diff Makefile m
< EMACS=emacs
> EMACS=c:/gnu/emacs-22.2/bin/emacs
< prefix=/usr/local
> prefix=c:/gnu
< org-footnote.el \
< DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir doc/.nosearch
> DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir
< lisp/org-footnotes.elc: lisp/org-macs.elc lisp/org-compat.elc

Well, a simpler way to do it is as follows.

  1. Issue a git pull
  2. If the Makefile has a conflict, rename the file and issue a git pull again
  3. Generate a patch file by issuing diff -e NEWfile OLDfile > foo.patch
  4. apply the patch on the Makefile as patch Makefile foo.patch
  5. The edits that one has made is re-applied on the new Makefile
$ diff -e Makefile m
DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir
$ diff -e Makefile m > b.patch
$ patch Makefile b.patch
$ make

Since I don't make any changes to org-mode codebase and the only thing that has to be changed everytime Makefile changes is the path info, this is a bit faster than editing the Makefile everytime.

Though it took me sometime to figure it out and there's still this nagging doubt whether there's a even simpler way.

Any ideas?

EDIT: Just realised that the patch file will have to edited to have ONLY the changes you want else it will remove the newer lines added to other parts of the Makefile. So, this post is kind of wrong and displays a slightly addled view of patching AND version control.

Looks like PUBLIC FAIL!


Anonymous said...

Have you tried git stash/git pull/git stash pop ? Your scenario is explicitly mentioned in the man page.

sivaram said...

no, I haven't. will read it up. thanks for that.

Anonymous said...

There's a new FAQ entry that covers this at

It uses a local branch for custom changes that are kept on top of the upstream code and should do exactly what you want. After setting it up just 'git pull' on your local branch normally and it just works.

The page will update soon to include details of how you deal with conflict resolutions during a pull operation.


Unknown said...

The link Bernt mentioned no longer works, it is now:

- Carsten