I've issued the following command
git rm --cached .idea
on my develop branch, 'cause i don't want to track ide config files. Files have been removed from index but they're still on filesystem, which is exactly my original goal.
Now when i try to checkout another branch, git fails because they're still in the index of the other branch - this is expected.
However, i need to remove these files from the index of any branch, so how can i issue the same git rm --cached command on a branch i can't checkout to?
Solved
If the file on the other branch is the same as the untracked file on the disk, you can git checkout -f, and then git rm --cached. If not, and you want to save the untracked file without git's knowledge, you must do exactly that: put it away in ~/tmp or something, clean up git's view, and mv it back to the repository directory. Also, put it in .gitignore immediately to avoid tracking it by mistake.
Faced with the same situation, I tend do this until all BRANCH_WHERE_FILE_REMAINS are gone.
git rebase BRANCH_WHERE_FILE_IS_REMOVED BRANCH_WHERE_FILE_REMAINS
Note: This doesn't cause checking out of commits where .idea remains, because rebase's cherry-picking is based after the commit where the file is already removed.
However, note that if at any point you do git rebase --abort, rebase will try going back to a commit where .idea was still in the index, and you'll probably face trouble there. (Backing up of .idea is recommended before attempting.)
BRANCH_WHERE_FILE_IS_REMOVED can just be the commit-id if there's no such branch.
No comments:
Post a Comment