Questions tagged [git-clean]

a git command that removes untracked files from a repository's working tree

git clean is a command that removes untracked files from a repository's working tree, starting in the directory from which it was called.

Resources

56 questions
1224
votes
14 answers

How can I revert uncommitted changes including files and folders?

Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?
MEM
  • 30,529
  • 42
  • 121
  • 191
393
votes
4 answers

Reduce git repository size

I tried looking for a good tutorial on reducing repo size, but found none. How do I reduce my repo size...it's about 10 MB, but the thing is Heroku only allows 50 MB and I'm no where near finished developing my app. I added the usual suspects (log,…
sent-hil
  • 18,635
  • 16
  • 56
  • 74
175
votes
18 answers

Can I restore deleted files (undo a `git clean -fdx`)?

I was following the instructions on making github pages, and forgot to move down into my git sub directory. As a result, I just nuked an entire directory of documents with git clean -fdx. Is there any way I can undo this terrible mistake?
Eric
  • 95,302
  • 53
  • 242
  • 374
99
votes
7 answers

Git pull - Please move or remove them before you can merge

I am trying to do a git pull origin master from my server but keep getting the error: Please move or remove them before you can merge. There are no untracked files, but it seems like it has issues with the ignored files for some reason. I tried…
Brett
  • 19,449
  • 54
  • 157
  • 290
98
votes
6 answers

Git checkout/pull doesn't remove directories?

I've got my repo @ github. I did some work at home and pushed it to github. It involved some deleting of files and directories. Now I'm on my work box, which had a copy of the code before deleting the files and directories. I issued the…
mculp
  • 2,637
  • 1
  • 25
  • 34
57
votes
5 answers

Git: Exclude a file with git clean

i'm working on a big python project, and i'm really sick if .pyc and *~ files. I'd like to remove them. I've seen that the -X flag of git clean would remove untracked files. As you can imagine, i'm not tracking .pyc nor *~ files. And that would make…
santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
40
votes
3 answers

How to preserve all ignored files in git clean -fd?

When I have .gitignore data/* and run git clean -fd, the data folder and all its content files are deleted. What I want is to delete all unrevisioned files in a git repo while excluding all ignored files (i.e. DON'T delete gitignored files). What…
Danny Lin
  • 2,050
  • 1
  • 20
  • 34
31
votes
1 answer

Difference between git reset --hard and git clean

Hi I am curious about the difference between these two commands. When they introduce here: https://www.atlassian.com/git/tutorials/undoing-changes Looks like git reset --hard also sets both the staging and the working directory to match the latest…
AlexWang
  • 369
  • 1
  • 4
  • 7
21
votes
5 answers

git clean: What does "Would not remove" mean?

When I run git clean --dry-run the results are a bit like: Would remove an_untracked_file Would remove an_untracked_file_2 Would not remove some_unrelated_folder/subfolder/ The "unrelated" folders are tracked and have had no changes, so I would not…
nonot1
  • 2,788
  • 4
  • 25
  • 41
21
votes
7 answers

Git clean is not cleaning untracked files

I'm getting the "The following untracked working tree files would be overwritten by checkout...please move or remove them before you switch branches" error. The common fix appears to be git clean When I type that in, I get no error, but nothing…
DA.
  • 39,848
  • 49
  • 150
  • 213
15
votes
3 answers

Git: need to recursively 'git rm' the contents of all bin and obj folders

Someone by accident just commited all of their bin and obj folders to our repo (there are around 40 such folders). I would like to do a git rm -r on all of these folders. Is there a command to do this?
Jacko
  • 12,665
  • 18
  • 75
  • 126
11
votes
1 answer

How to use git clean remove all file list in .gitignore?

mkdir repo cd repo git init mkdir temp touch temp/in.tmp touch out.tmp echo '*tmp' > .gitignore when use git clean -Xn it show Would remove out.tmp but I want to remove temp/in.tmp together git clean -Xdn not work too, but cd to temp directory and…
Hanlin
  • 835
  • 10
  • 26
10
votes
1 answer

What is the difference between "git checkout -- ." and "git reset HEAD --hard"?

This is not a general question about what '--' does, as in the marked duplicate. This is a git-specific question asking for clarity on what the operational differences are between the mentioned commands. If I want to clean out my current directory…
M_M
  • 1,955
  • 2
  • 17
  • 23
9
votes
1 answer

git-clean with GitPython

Is there any way to do something like git clean -d -x -f using GitPython? I need to reset working directories and want to get rid of all unversioned files without deleting the whole folder (except for .git) and checking out again.
Paddre
  • 798
  • 1
  • 9
  • 19
7
votes
2 answers

Why does git checkout not delete new files?

Suppose I create (but do not commit) a file file.txt, and then type git checkout HEAD or git checkout HEAD .. I thought git checkout basically overwrote your current working files with the snapshot at the commit you give it, so I would have thought…
Jack M
  • 4,769
  • 6
  • 43
  • 67
1
2 3 4