In svn, sometimes I delete a local file then use 'svn update' to get a clean copy. How can I do it in git? git pull/fetch didn't work. The only way I figured out is use diff which is incontinent. Thanks. I'm using tortoiseGit.
Files are staged and committed differently in git and svn. The gist of the difference from git’s perspective is that with git a file is versioned through a staging area called an index, from there it goes as part of a commit to the local graph of commits that your branch points to, and from there it is propagated to the remote graph of commits when you push the branch to the remote server.
While acknowledging that “latest” is somewhat misleading, to simplify a bit, there are four “latest” file versions: the one in the working tree, the one in the index, the one in the local branch and the one in the remote branch. And the local and the remote branch are not necessarily in sync. So when you say that you want a clean copy of a file you have to refine the question first - and answer to yourself which of the four you are after.
$ git checkout -- /path/to/file
$ git checkout HEAD -- /path/to/file
$ git checkout origin/master -- /path/to/file
$ git fetch
$ git checkout origin/master -- /path/to/file
$ git pull
$ git checkout master -- /path/to/file
Try using git checkout:
git checkout <filename>
Note that if you are in the middle of a merge or rebase, and want to resolve a conflict
you need to add --ours or --theirs to let git know which <filename> you want.
e.g.:
git checkout --ours <filename>
If you want a filename as it appeared elsewhere in the history (or as it appears on another branch)
git checkout <branch-name or SHA> -- <filename>
Note the -- separates git REF names from filenames.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With