Git invert staging area

后端 未结 4 1496
滥情空心
滥情空心 2021-02-13 16:14

I have got changes in my staging area, and others not staged yet (some files have changes both in and out the staging area). I would like to invert the content of the st

4条回答
  •  醉酒成梦
    2021-02-13 16:44

    This is what I use to solve this issue.

    First git reset which will remove all the files from 'staging' to 'files not staged for commit'. The files that are in both 'staging' and 'files not staged for commit' will keep your most recent changes that are currently in your 'files not staged for commit'

    then

    git add /path/to/file the specific files you need to add to staging

    Not exactly a short-cut, but it gets the job done

    Inversely, After you git reset, you could git checkout /path/to/file for the files that are currently 'not staged for commit' which you don't want to add to staging. This will remove specific files from 'not staged to commit'

    then run git add . which will add all files in 'not staged for commit' to 'staging' - whichever is easier for your situation

提交回复
热议问题