Git: How to remove file from index without deleting files from any repository

前端 未结 7 1902
情深已故
情深已故 2020-11-30 17:17

When you use

git rm --cached myfile

it doesn\'t delete from the local filesystem, which is the goal. But if you\'ve already versioned and c

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 17:54

    Had the very same issue this week when I accidentally committed, then tried to remove a build file from a shared repository, and this:

    http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

    has worked fine for me and not mentioned so far.

    git update-index --assume-unchanged 
    

    To remove the file you're interested in from version control, then use all your other commands as normal.

    git update-index --no-assume-unchanged 
    

    If you ever wanted to put it back in.

    Edit: please see comments from Chris Johnsen and KPM, this only works locally and the file remains under version control for other users if they don't also do it. The accepted answer gives more complete/correct methods for dealing with this. Also some notes from the link if using this method:

    Obviously there’s quite a few caveats that come into play with this. If you git add the file directly, it will be added to the index. Merging a commit with this flag on will cause the merge to fail gracefully so you can handle it manually.

提交回复
热议问题