6

I have written a commit to a file from gitk by right-clicking the commit and selecting "Write commit to file".

How do I apply the commit from this file? I can do git apply, git add and git commit combo, but isn't there a one-step command to just take the output (with the commit message and meta-data) and commit it as it is?

Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • 1
    This is very poorly stated - use the same terminology as git. I do not understand what you mean by 'written a commit to a file' and I maintain git-gui. Did you commit changes to a file and then generate a patch somehow? The details matter if you expect to receive useful assistance. How was the patch generated - *exactly*. As you have noted, git apply and git am accept different format files - one expects patches, the other emails with inline patch and commit information. I suspect the answer below is actually correct. – patthoyts Apr 19 '12 at 15:12
  • 3
    @patthoyts How else do I describe clicking the button "Write commit to file"? – Šimon Tóth Apr 19 '12 at 15:23
  • Looks like there is a "write commit to file" option in `gitk`, which brings up a dialog that performs the command `git diff-tree --stdin -p --pretty`. `git am` apparently doesn't understand this format. `git apply` is only for applying diffs, i.e. it won't create the commit object. – Abe Voelker Apr 19 '12 at 15:31
  • @AbeVoelker So I shouldn't use this option at all, and use `git format-patch` instead? – Šimon Tóth Apr 19 '12 at 15:33
  • @Let_Me_Be That might be the easiest option. There may be a way to coerce `git am` into understanding the format, but I don't do patches much so not sure. – Abe Voelker Apr 19 '12 at 15:35
  • @AbeVoelker Thanks, could you reformulate your comments into an answer? – Šimon Tóth Apr 19 '12 at 15:36
  • There is *no* button labelled "Write commit to file" in git-gui. gitk is a different application. – patthoyts Apr 19 '12 at 15:57
  • 1
    @patthoyts `git gui` -> LMB "Repository" -> LMB "Visualise All Branch History" -> RMB desired commit -> LMB "Write commit to file" – Šimon Tóth Apr 19 '12 at 16:01
  • 1
    @patthoyts And please, go bother someone else with your trolling. – Šimon Tóth Apr 19 '12 at 16:02
  • 1
    Hi Let_Me_Be, the `git gui` -> LMB "Repository" -> LMB "Visualise All Branch History" sequence, under the hood, fires up a `gitk` instance, hence the confusion about Pat's response from his maintainer viewpoint. The two parts, `git-gui` & `gitk` are separately maintained. – Philip Oakley Apr 20 '12 at 15:22

4 Answers4

4

No-one seems to have provided an actual answer to the question, so here's what I found from https://github.com/sinsunsan/archiref_wiki/wiki/Git-howto

patch -p1 < patch-file

This takes the patch file produced by 'Write commit to file', tells it to ignore the first level of path (-p1) i.e. a/, b/ in the file, and apply to the current files on disk. The result is then in your working tree, and can be committed as a new commit:

git commit -am'Commit message here please.'
Neek
  • 7,181
  • 3
  • 37
  • 47
2

I'm using Linux, but I think I see what you're talking about. In gitk there is a "Write commit to file" option when right-clicking a commit, which brings up a dialog that performs the command git diff-tree --stdin -p --pretty by default.

git apply is only for applying diffs, i.e. it won't create the commit object so that shouldn't be used. git am should be the correct tool for performing this operation, as it creates commit objects. However, it doesn't understand the format output by the above command, and creates the error you are seeing.

The easiest option is probably to create the patch using a format git am understands using git format-patch instead of git diff-tree. There may be a way to coerce git am into understanding the git diff-tree format, but I don't do patches much so am not aware of it offhand.

Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
0

git am might do what you're looking for. It takes patches as generated by git format-patch as input. I don't know what git-gui is spitting out.

Phil Miller
  • 36,389
  • 13
  • 67
  • 90
  • "Patch format detection failed." Kind of weird since I just generated the file with the same git on the same machine on the same repo. – Šimon Tóth Apr 19 '12 at 14:19
  • How is this supposed to work? The manual page talks about a mailbox as a parameter, which would seem to indicate that this isn't the correct command. – Šimon Tóth Apr 19 '12 at 14:33
  • 1
    After doing some digging, the command does indeed expect a mailbox format, not a patch. – Šimon Tóth Apr 19 '12 at 14:50
0

I solved this problem in a tricky way. And in a tricky way I've got it, I gues.

I took my old master branch I worked on some time ago and now decided to carry it commit-by-commit in to my new project. And it seems that back in days I messed around with my file modes between one commit and another.

So after consistently creating theese commit files for move-over by hitting gitks "Write commit to file" I've started to "git apply" commit- files one by one while editing some of them in notepad. Here is a sample of fix that worked for me.

I tweaked such parts

index 30d5c59..63e26fb 100755

to make them look like this

old mode 100644
new mode 100755
index 30d5c59..63e26fb

Hope this would help someone else.

Pandga
  • 1