1

Hi pushed to repository several solutions. Unfortunately, I didn't setup .gitignore. At the moment my repository stores dozens bin/Debug and Obg/Debug folders. Is there a way to delete them at once ?

Imugi
  • 161
  • 1
  • 3
  • 13

3 Answers3

1

If only one commit is affected, then git rm the files, then create your .gitignore then git add -A; commit --amend --no-edit then git push --force origin master. Warning: --force can break things for collaborators, but if no-one pulled your commit yet, then it should be okay.

If there are multiple commits you should look at this guide.

In the above answers I assumed you wanted to save disk space. If that's not an issue, then just simply git rm the files, add them to .gitignore and create a new commit.

Leventix
  • 3,789
  • 1
  • 32
  • 41
0
find ./ -name Debug | xargs rm -rf     
git add --update    
git commit
git push

After there command, those files will not been tracked by git any more.

gzh
  • 3,507
  • 2
  • 19
  • 23
  • `rm -rf` combined with output from other commands is really dangerous. You should probably run `find ./ -name Debug` first and check the output, or leave out the `f` flag so it will ask for confirmation. – Leventix Feb 27 '16 at 16:05
  • @Leventix you are right, confirmation before deleting will be safer. Thank you. – gzh Feb 27 '16 at 16:15
0

... At the moment my repository stores dozens bin/Debug and Obg/Debug folders.
Is there a way to delete them at once ?


Before answering let's understand how does git handle committed content in order to understand what need to be done.

Every time you execute a git add git calculate the SHA-1 of the file and start to track it from this point on.

Every time you execute a git commit the content is added to git and from this point on git track any changes made to this file.

If you decide to add this files to .gitignore at this time it will have no effect, since as explained before git will continue to track the content.


How to tell git not to track commited content?

As explained above, once content is committed to the repository git will continue to track it.

At this we need to decide in which way we wish to fix it:

  1. Leave the wrong content in git
  2. Remove the content from git history

Leave the wrong content in git

This is the simple case, we will simply delete the track content from git and since the file is deleted and is already in the .gitignore it will not be tracked from this point on

# add the content to git ignore
# delete the content from git (not from file system) and commit it
git rm --cached <files..>

git commit -m "Removed files..."

Remove the content from git history

This part is bit more tricky and risky and you several options as well.
Read this post: How to move HEAD back to a previous location? (Detached head)

Very detailed with a walkthrough for each option on how to fix it.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167