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

In svn working directory i can

  • make some changes to the files in the working directory
  • delete all the changes I made 'rm, all the source files in this directory, but keep my .svn directory)
  • getting what the patch cable was supposed to use with 'svn update' and svn will load all the source code back into my working directory.

Is there an equivalent command in git? could you tell me how to do this?

+6
git svn
source share
3 answers
git reset --hard 

which is synonymous with the word " git reset --hard HEAD " should be what you are looking for.

Use it with care, as it effectively removes any current changes in your working directory. See " Cancel in Git "

Note: as Charles Bailey mentions in the comment and in his answer , this will not delete unsolicited files.
For this, git clean is the right tool. See His answer for more , but also a SO question. How to remove unnecessary files from your working copy of git? "or Git -Ready article" cleaning up unused files . "

So, if we want to do a big cleanup:

 $ git clean -n -d -x 

This command will clear the files listed in the .gitignore project file and also delete other files and directories that are needed. As always, take precautions when working with git clean and make sure you double check that you are really uninstalling.

Please note that you can move your files without a trace .

+9
source share
  • You want to discard all changes to tracked files in your working directory
  • You are at the root of your working directory

    $ git.

This will recursively check (restore) every file that is tracked from the last commit in the current branch (head).

+4
source share

Assuming you are at the root of your working copy.

If you want to do a clean one to remove any unprocessed files, first do a dry run to make sure it is not going to knock anything. (You might want to examine the directory (-d) and also use ignore options (-x).)

 git clean -n 

Then run it "for real."

 git clean -f 

Then check for fresh unmodified files from the index for all of your monitored files.

 git checkout . 
+2
source share

All Articles