简体   繁体   中英

How to untrack file/folder in all branches in git?

I accidentally added a folder and a file to git index in the master branch. Then I created two branches and both have the folder and file in the index.

When working in branchA I noticed that and did git rm --cached <file> followed by git commit -m "removed unwanted file" , however when I try to switch to branchB I get the following error

error: The following untracked tree files would be overwritten by checkout: <filename>. Please move or remove them before you can switch branches.

Is there a way to untrack (remove from git index) a folder and/or file from all branches?

git update-index should do what you want

This will tell git you want to start ignoring the changes to the file
git update-index --assume-unchanged path/to/file

When you want to start keeping track again
git update-index --no-assume-unchanged path/to/file

Github Documentation: update-index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM