Create a git patch from the uncommitted changes in the current working directory

后端 未结 7 1527
小蘑菇
小蘑菇 2020-11-27 08:53

Say I have uncommitted changes in my working directory. How can I make a patch from those without having to create a commit?

7条回答
  •  旧巷少年郎
    2020-11-27 09:31

    I like:

    git format-patch HEAD~
    

    where is number of last commits to save as patches.

    The details how to use the command are in the DOC

    UPD
    Here you can find how to apply them then.

    UPD For those who did not get the idea of format-patch
    Add alias:

    git config --global alias.make-patch '!bash -c "cd ${GIT_PREFIX};git add .;git commit -m ''uncommited''; git format-patch HEAD~1; git reset HEAD~1"'
    

    Then at any directory of your project repository run:

    git make-patch
    

    This command will create 0001-uncommited.patch at your current directory. Patch will contain all the changes and untracked files that are visible to next command:

    git status .
    

提交回复
热议问题