Git stash uncached: how to put away all unstaged changes?

前端 未结 4 739
孤城傲影
孤城傲影 2021-01-30 00:27

Suppose two set of changes are made in a project versioned by git. One set is staged and the other is not.

I would like to recheck staged changes by running my project a

4条回答
  •  遥遥无期
    2021-01-30 01:09

    I found the marked answer did not work for me since I needed something which truly stashed only my unstaged changes. The marked answer, git stash --keep-index, stashes both the staged and unstaged changes. The --keep-index part merely leaves the index intact on the working copy as well. That works for OP, but only because he asked a slightly different question than he actually wanted the answer for.

    The only true way I've found to stash unstaged changes is to not use the stash at all:

    git diff > unstaged.diff
    git apply -R unstaged.diff
    

    git checkout -- . will also work instead of apply -R.

    Work work work...

    git apply unstaged.diff
    rm unstaged.diff
    

提交回复
热议问题