简体   繁体   中英

git am from branch to master

I'm working together with a college of mine in git. I'm working on a branch, and he's working on the master. I've done some work related to his files on my branch, and I decided to send him a patch file. I created the patch with git format-patch , and sent it to him. when he tries to apply the patch using git am he get's the following message: previous release directory

It's probably because the patch arrived from a different branch.

Is there a way for him to use the patch on the master branch ?

Note: I'm using git am , and not git apply to keep commit-id that is generated for jetty. I still want the commiter to be me on his local repository.

Consider using one of the two solutions when dealing with patches that fails to apply properly :
(article from bugdromer ):


The simplest way for dealing with it would be to:

  • git am --abort ,
  • apply the patch manually by patch -p1 < PATCH ,
  • resolve the conflict by hand,
  • and finally commit with git commit -a .

But in this case you'll have to rewrite the commit message, which is not very nice. There is a more clever way.


You can find the corresponding patch file stored in .git/rebase-apply , and named " 0001 " (the name of the dir where the patch is stored changed recently, this is tested with 1.7.4.1).
At this point:

  • you can use git apply for applying the patch, which is the git equivalent of the patch command ,
  • and fix the conflicting files the usual way (you check the .rej files, compare them with the conflicting files and finally add the fixed files to the index):

Example:

$ git apply PATCH --reject
$ edit edit edit
$ git add FIXED_FILES
$ git am --resolved

and you're done!
In other words, since git am didn't change the index, you need to

  • git apply --reject the patch (stored in .git/rebase-apply ),
  • fix conflicts by hand,
  • add the changed files and
  • finally tell git that you resolved the trouble.

The advantage in this case is that:

  • you don't need to re-edit the commit message,
  • and in the case you're applying a set of patches (that is you're using git am PATCHES , where PATCHES is a mailbox), you don't have to git abort and run git am again.

Try the --3way option of git am :

 -3, --3way When the patch does not apply cleanly, fall back on 3-way merge if the patch records the identity of blobs it is supposed to apply to and we have those blobs available locally. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM