简体   繁体   中英

Remove file from all Git branches (Can't Commit a Git RM only)

My team is working with Visual Studio Online's Git system, and we're trying to find a way to remove the applicationhost.config file (should be local to each team member's machine, having a copy synced with Git is just a hassle and means having to do undo the changes when committing, or the next person have to restart visual studio to regenerate it if they pulled in someone else's file).

I've tried a bunch of different git commands to simply untrack this file from this point forward, and I can't seem to get it to work.

git filter-branch --index-filter "git rm -f --cached --ignore-unmatch path/to/filename" -f HEAD --all 

This created a duplicate of every commit (250) since the applicationhost.config file was introduced into our repo. I didn't pull it in to master because we were concerned with the 250 commits being overwritten and not being able to undo them.

git update-index --assume-unchanged path/to/file 

I tried this one, and it seems like it does ignore the file in the branch you are in, but when you try to switch to a different branch the new branch will inform you your applicationhost.config file is different, and won't allow you to switch. It also makes it harder to switch, since because the file is ignored, you cant go to changes and undo the changes to that file.

git rm -f --cached --ignore-unmatch path/to/filename

This is the most frustrating, because I believe it does work, but I have no way of committing it. I can go from a direct pull off of the master branch, make a new local branch, type in the rm command above, and see the following in the changes: first . I cant add the file from the Untracked files to the files, clicking has no effect. But when I try to click the commit button, all I get is two (It says there is nothing to commit). This happens the millisecond I hit the commit button.

I'm kind of at a loss here then as to how I can actually get all of our branches (we probably have about 15-20) to stop tracking applicationhost.config, without needing to re add all 250 commits made since it was added. It would be ok if it was just something we could run, push to master, and then merge from master into our other branches.

Help?

This created a duplicate of every commit (250) since the applicationhost.config file was introduced into our repo.

That's right. Commits are irrevocable. All you can do in any repo is forget them, by rehanging all the branch and tag labels on new commits that don't have the bad parts anywhere in their history.

Create the entirety of the new history you want, and force-push it or fetch and hard reset it over any existing history.

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