git stash and edited hunks

前端 未结 3 847
自闭症患者
自闭症患者 2021-02-03 10:29

I totally love git add -p and git stash but I occasionally have the following problem, which is reproduced by the following sequence of commands:

3条回答
  •  有刺的猬
    2021-02-03 10:56

    To create and test an index containing part of the working tree changes, including manually edited hunks, do:

    git add --patch 
    
    git stash --keep-index
    
    
    
    git reset --hard
    
    git stash pop --index
    

    At this point there are no conflicts, and the repository, index, and working directory are in the state immediately preceding the git stash. You can now git commit the indexed changes.

    Of course, this is rather weird and not very intuitive and I would really like to know whether there is an easier way to do this.

提交回复
热议问题