top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do I remove a file from all branches in a git repository but leave it on the file system

+1 vote
640 views

At some point I added a large file into a git repository. It now exists on multiple branches, possibly with some changes to it. I'd like to remove it from git, but leave its current form (say the one on the master branch) on the file system.

I tried (on a dummy git archive)

git filter-branch --index-filter 'git rm --cached --ignore-unmatch bigfile' master branch1 branch2

That, however, does not leave a copy of bigfile on the file system.It isn't clear to me why not, though the description of the --tree-filteroption to filter-branch (I'm using the --index-filter option, but is is "similar") states:" (new files are auto-added, disappeared files are auto-removed ... )".
Is there a direct way to do what I want, with git? I've found similar requests;none of the responses point out that the above command actually deletes the file from the file system.

posted Aug 19, 2013 by Majula Joshi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

You've figured out how to remove it from the repository. To keep a copy around, I would extract it explicitly with "git cat-file" and put it somewhere outside of the working copy before doing "git filter-branch".

answer Aug 19, 2013 by Mandeep Sehgal
+1 vote

If it is still in the working directory, why not rename it (using OS commands, not git command), do the git command to remove all traces as previously mentioned, then rename it back?

answer Aug 19, 2013 by Abhay Kulkarni
Similar Questions
+5 votes

basically, I've got clones of some expensive-to-build projects (node.js), and I have changes that I want to rebase/cherry-pick onto dev and stable branches.

I know I can push to a remote, then pull into my other, and keep the two on different branches so the builds don't get out of date. But, I think I'd like it if they all just shared the same objects, branches, etc...

Could I symlink together my .git{branches,config,hoks,logs,objects,packed-refs,refs} directories? Is this just going to kill me later?

+2 votes

How do I switch to a hash on a branch without creating moving to a new branch? Say I'm currently at the HEAD of master, and its hash is aaa. I want to stay on master, only switch to a previous hash... (say eee...)

I know I can use the HEAD~ or whatever, but I'd like to find out how to do it based only on a hash...

+2 votes

I would like to know what are the best practices when creating a new branch. For example. If I get a request to do update website title from XYZ to ABC; then should I create a branch named; "Update Title"? Or I should prefix this as suggested here (http://stackoverflow.com/questions/273695/git-branch-naming-best-practices). Are there any official prefixes?

Also I am concerned about the following; Let us say I create the branch named "Update Title". Finish the change. Merge back with Master. I then get another request to change title from ABC to DEF. Can I create another branch "Update Title". Will not this be confusing?

+1 vote

I have heard conflicting statements about the impact of branching in git. Let's say we have 100 feature branches that are all stored in a remote repo, would that affect performance (CPU/network) in a noticeable way ? How about 1000? 100,000 branches? In other words how does git scale with regards to number of branches?

+1 vote

When I run git clean -xfd, git deletes my tags file. I have the tag file listed in gitignore, but how do I tell git not to remove the tags file.

...