Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove left over .rej files after reverting from a git patch?

Tags:

git

I recently applied a patch to my repo which I afterwards realized was the wrong thing to do. I applied the patch with the "--reject" parameter, so it applied the changes that worked and created .rej files for the rest.

I am fairly new to git, so I may not have gone back the right way because now I am back to a previous commit and everything is working fine, except I have a lot of .rej files scattered around my code base. I went back to a previous commit and did a "git reset --hard" to get rid of all the files that applying the patch checked out.

I can't find any information on why I still have these .rej files even though I have nothing checked out. I know that I probably went about reverting from the patch incorrectly, and it seems that there is usually a better alternative to applying a patch anyways, but does anyone know the proper way to get rid of these rejects?

Thank you!

like image 939
Methos Avatar asked Mar 25 '14 18:03

Methos


2 Answers

Like most git commands, git reset --hard doesn't touch files that git doesn't know about.

To delete them manually, first use git clean -n to show all files in the working directory that are not tracked by git. Make sure there's nothing listed that you want to keep. Then use git clean -f to actually delete the files.

There are two options you might want to know about:

  • git clean -xf also removes files ignored by git

  • git clean -df also removes untracked directories

like image 145
user3426575 Avatar answered Nov 02 '22 22:11

user3426575


git clean may do what you want.

Or you can remove files manually with find . -name \*.rej | xargs rm.

Or you can remove all files, except .git in your repo and then do git checkout . which will restore the files under source control.

like image 33
ArtemB Avatar answered Nov 02 '22 23:11

ArtemB