5

I added files ending with ~ in my repository in GitHub and now I want to remove them.

For example I added:

README.md 

and the file

README.md~ 

was added as well.

Any help please?

2
  • So what do you want exactly? To remove them (git rm), to prevent them from being added again (man gitignore), or to rewrite your history so they appear to have never been added? Commented Jun 23, 2011 at 11:59
  • rewrite history so they appear to have never been added and removed them from current repository! Commented Jun 23, 2011 at 12:00

3 Answers 3

10

For ignoring all the file ending with a ~ you should add this to the .gitignore file at the top-level in your repository (alongside the .git directory).

# Ignore all emacs backup files *~ 

Then, for changing the history and removing the README.md~ file, you can either do it manually with git rebase --interactive or try to use git filter-branch:

$ git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch README.md~' HEAD 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot mate! I run git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch README.md~' HEAD after putting .gitignore. That fixed everything!
2

You should make use of gitignore to ignore these files you don't wish to appear in your repository.

To remove the files, you can use

git rm README.md~ 

then commit as usual.

2 Comments

Is there a way to remove all files ending with *~ . And how can I add this to .gitignore ? Thanks
You could try something like: git rm *~ Then add to your .gitignore file: *~
0

If you want to rewrite the history, the easiest way is probably to use git rebase -i:

  1. remove the file with git rm, add *~ to your .gitignore, and commit your changes
  2. git rebase -i commit_before_the_file_was_added
  3. in your text editor, put the line of your last commit just after the one of the commit in which you added the file, and change "pick" to "fixup"
  4. save, exit, watch magic happen
  5. double-check that your history is fine, and git push -f.

...or you can use what's suggested in this question.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.