user1884325
user1884325

Reputation: 2550

what is the git equivalent of SVN UPDATE?

With SVN you can delete a local file (put it in the trash can) and restore it by running svn update after the delete. The SVN client will simply pull a fresh copy of the file (and nothing else gets touched in the directory).

I haven't been able to figure it out with GIT.

I'm using Tortoise Git on Windows and a 'pull' or a 'fetch' doesn't restore the file. I don't want to have to check out the entire repository (clone) again...

Upvotes: 0

Views: 2258

Answers (2)

Nischey Grover
Nischey Grover

Reputation: 11

You could do "check for modifications" and then you ll see a list of deleted files. Right click any file and chose revert

Upvotes: 1

Alex Wolf
Alex Wolf

Reputation: 20138

You would be able to restore all deleted files by using a combination of commands. Obviously this only works for files you deleted but whose deletion you didn't commit yet.

The command chain in question could look like this:

git checkout -- $(git diff --name-only --diff-filter=D)

As torek already explained in the comments git checkout is the command that restores the file, the interesting part happens at the git diff command.
The --name-only option tells diff to only print the filenames of the changed files, while the --diff-filter=D takes care that everything but deleted files is getting ignored.

For easier usage you can create an alias which will also allow you to use the command in CMD. Creating an alias could look like this:

git config --global alias.restore '!git checkout -- $(git diff --name-only --diff-filter=D)'

You will have to use double quotation marks (") on CMD.

You will then be able to use the command easily with git restore.

For further information you can take a look at the git diff, checkout and config documentation.

Upvotes: 0

Related Questions