tags:

views:

47

answers:

3

I erroneously added some local project files to a git repository and committed/pushed them.

I'd like to delete these files from the remote repository, keep them locally, and ignore them for future commits/pushes.

What's the best way to go about this?

+1  A: 
  1. Create a new branch which has the commit with the files.
  2. Reset the original branch back to where it used to be.
  3. Do a push -f to forcefully revert the remote backwards (WARNING: This will "break" repositories which have those commits already pulled - its undoable, but manual drudgery).
Yann Ramin
+1  A: 

Well add them to .gitignore (line separated filenames in the main directory of the repo and then follow this guide: http://help.github.com/removing-sensitive-data/. Finally git push -f to forcibly overwrite the remote repo.

FallingBullets
+3  A: 

The cleanest solution is to:

  • git rm --cache the extra files locally (note the --cache option to keep those files in your working directory),
  • add them to your .gitignore file and git commit -A -m "..." after that,
  • push your branch (no history rewritten, but previous history will keep references to those files).

If you think not too many people have pulled from your remote repo (ideally, none), you could:

  • fix your commit history locally
    (git rebase --interactive first-commit-with-files^: the '^' referencing the parent commit of the first one where you did introduce the bad files.
    git rm --cache the files, then replay the other commmits unless some of them have also made modifications to the same files.
    Other solutions here -- git filter-branch or git rebase),
  • push --force your branch,
    (but then, be prepared to point out people to the RECOVERING FROM UPSTREAM REBASE section of the git rebase man page).
    (see definition of upstream here)
VonC