Comment by oelmekki
7 years ago
Maybe it's not worth being in there because of how simple it is, but I guess it would be useful for newcomers:
# Oh shit, I've changed 200 files and want to revert to the state of this morning
$ git add . && git commit # often. Very often.
$ git reset --hard commit_id
I think this is bad advice for git newbies two reasons:
1. ‘git add .’ is dangerous and should be avoided IMO, in case you ever have files around that you don’t want to commit. I frequently do. It’s better to ‘git commit -a’, and to just remember to run ‘git status’ frequently and ‘git add’ any new files.
2. ‘git reset —-hard’ is dangerous as well for newbies, since it’s destructive. Better to ‘git revert’ or to ‘git checkout <sha>; git checkout -b <newbranch>’, such that you can always get back to where you were.
Wait, aren't you committing and immediately orphaning that commit? I think you should create a new branch or tag before the reset, otherwise how are going to get it back?
I guess you could rely on the reflog, but I don't think that's good practice.
lol, no, it's implicit there are many hours between the first command and the second one :)
It's purely commiting often to easily have checkpoints to revert to, nothing fancy (yet, incredibly useful).
git reset --hard for what!? If you are a newcomer making mistakes it is fine for the mistake to be in the commits. Just fix the problem and commit again.