Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'rm' + 'svn update' equivalent in Git?

Tags:

git

svn

In a svn working directory, I can

  1. make some changes in files in the working directory
  2. remove all the changes I made by 'rm all the source files in that directory, but keep my .svn directory)
  3. retrieve what the trunk supposed to by using 'svn update' and svn will download all the source back to my working directory.

Is there an equivalent command in git? can you please tell me how to do that?

like image 256
n179911 Avatar asked Jul 22 '09 05:07

n179911


1 Answers

git reset --hard

which is a synonym for "git reset --hard HEAD" should be what you are looking for.

Use it with caution as it would effectively delete any current change in your working directory. See "Undoing in Git"

Note: as Charles Bailey mentions in the comment, and in his answer, this would not removed untracked files.
For that git clean is the right tool. See his answer for more, but also the SO question "How do you remove untracked files from your git working copy?", or the Git-Ready article "cleaning up untracked files".

So if we wanted to do a major cleanup:

$ git clean -n -d -x

That command would clean up files listed under the project’s .gitignore file as well as removing other files and directories that aren’t necessary.
As always use precaution when running git clean, and make sure to double check what you’re really deleting.

Note, you might want to move your untracked files instead.

like image 59
VonC Avatar answered Oct 06 '22 01:10

VonC