On Sep 3, 12:25 am, andholt <andh...@gmail.com> wrote:
> A few days ago I accidentally committed a directory of generated
> images, so I removed them (git rm) and committed again. I then added
> the directory to .gitignore, and pushed to the remote repository. When
> I did so, it uploaded all of the image files, and proceeds to do so
> every time I push, even though none of them are in the commit (git
> status shows only the other files I change).
> Do I need to take the directory out of the .gitignore and remove it
> from a commit again? Is there something else I potentially did wrong?
> The other person working on the project does not get the files when
> pulling, so it appears to be something I did locally.
Git did not physically remove the files after you removed them in some
following commit simply because the commit referencing the wrong files
still exist and is reachable from at least one branch (your current
one) throught the chain of the commits following it. That's how VCS
works after all.

You have two ways of removing that files from the history: git-rebase
and git-filter-branch. The former is simpler and I'd recommend to try
it first.

The idea is to do interactive rebase (`git rebase -i`) specifying the
commit preceding the wrong one. Then, if the wrong commit does *only*
contain wrong changes, simply delete it from the rebase script you'll
be presented with and proceed.
If the wrong commit also contains other (needed) changes, mark it as
"edit" in the rebase script and then, when the git stops after putting
that commit's changes to the index, do `git rm --cached` for those
files you don't want. Follow this by `git commit --amend -C ORIG_HEAD`
and `git rebase --continue`.

Then you will have to push the updated tree with the -f ("force")
option because you have rewritten the history. And to actulally remove
the dangling blobs after history rewriting you have to run `git gc`.

Be sure to read git-rebase manual and [1] to understand what
additional measures
history rewriting implies.

History rewriting in general, including rebaising and branch filtering
is discussed in [2].

1. http://progit.org/book/ch3-6.html (the "Perils of rebasing" part).
2. http://progit.org/book/ch6-4.html
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to