Can I get a patch-compatible output from git-diff?

前端 未结 5 992
傲寒
傲寒 2020-12-07 07:43

I am doing something very simple wrong. I\'m trying to prepare an ordinary patch file, so I can reapply some changes:

$ git diff > before
$ git diff some         


        
5条回答
  •  囚心锁ツ
    2020-12-07 08:01

    If you want to use patch you need to remove the a/ b/ prefixes that git uses by default. You can do this with the --no-prefix option (you can also do this with patch's -p option):

    git diff --no-prefix []
    

    Usually though, it is easier to use straight git diff and then use the output to feed to git apply.

    Most of the time I try to avoid using textual patches. Usually one or more of temporary commits combined with rebase, git stash and bundles are easier to manage.

    For your use case I think that stash is most appropriate.

    # save uncommitted changes
    git stash
    
    # do a merge or some other operation
    git merge some-branch
    
    # re-apply changes, removing stash if successful
    # (you may be asked to resolve conflicts).
    git stash pop
    

提交回复
热议问题