Hmm …
Hmm …
Posted Nov 4, 2018 19:03 UTC (Sun) by smurf (subscriber, #17840)In reply to: Hmm … by epa
Parent article: Apache Subversion 1.11.0 released
That depends on whether you want to get a single file (or three), or go to a different commit. The latter refuses to overwrite things.
> what is the safe git command to bring back deleted files
There is none. If you overwrite a file that hasn't been checked in, it's gone, just like when you use "rm". In fact, if you try to "git rm" a modified file, it'll warn you.
Adding a warning option does make sense; I'll file a feature request.
Posted Nov 4, 2018 20:11 UTC (Sun)
by madscientist (subscriber, #16861)
[Link]
> It's more about 'git checkout .' which will silently overwrite every local change in the working copy.
Adding a "." causes a checkout of all (modified) files from the current directory down. It cannot go to a different commit.
For me, if I want to un-modify a file I use "git status" to see a list of modified files, and "git checkout filex filey ..." (perhaps copy/paste) to check out specific files. If I want to throw away everything I use "git reset --hard HEAD" or similar. I virtually never use "git checkout <directory>" and wouldn't suggest it to others, either.
> what is the safe git command to bring back deleted files
By this I assume you mean a committed file that you have deleted and then want to recover and not an untracked file that you've deleted.
The best way to know how to solve almost ANY issue in a workspace is to run "git status" and it will tell you how to undo it. For example, if you "rm somefile" and then decide you want it back, "git status" will tell you:
> Changes not staged for commit:
> deleted: Demo/readme.txt
If you use "git rm somefile" then decide you want it back, "git status" will tell you:
> Changes to be committed:
> deleted: Demo/readme.txt
And finally when in doubt, I use "git stash" to stash modified files before doing any kind of bizarre operations on a repository where there are modifications I want to preserve, just in case.
Posted Nov 5, 2018 6:59 UTC (Mon)
by epa (subscriber, #39769)
[Link] (1 responses)
'git checkout .' will appear to work for this task but it is highly dangerous, since it unconditionally trashes any other local changes. As another poster noted, there doesn't seem to be a command which does it, short of running 'git status', looking for 'deleted' lines, and running 'git checkout' over those.
Now, you may say that this isn't a sensible way to work, and the right way to revert changes in a file if you messed it up is to run 'git checkout FILE' directly. Not to just delete the file and then hunt for the right incantation to bring it back. But rightly or wrongly it is a natural human reaction to say "I really messed this up, let's just delete it and start again".
I did raise the feature request on the mailing list: https://public-inbox.org/git/loom.20150603T104534-909@pos...
Posted Nov 13, 2018 22:51 UTC (Tue)
by arnout (subscriber, #94240)
[Link]
You might want to give 'git checkout -p' a try.
Hmm …
> (use "git add/rm <file>..." to update what will be committed)
> (use "git checkout -- <file>..." to discard changes in working directory)
> (use "git reset HEAD <file>..." to unstage)
Hmm …
Hmm …
> from the current commit (or from git's index, if they happen to be in there).