Friday, July 14, 2017

Use Git to Undelete Accidentally Deleted Files

One of the benefits of using Git for version control is that Git can recover accidental deleted files and accidental changes.

For example, if I changed a file named: sessions_helper_test.rb  by mistake. I can type the status of the changes file using the git status command.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   test/helpers/sessions_helper_test.rb

no changes added to commit (use "git add" and/or "git commit -a")

I can undo my changes such as deleted file using the git checkout -f command.
$ git checkout -f
Your branch is up-to-date with 'origin/master'.

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

No comments:

Post a Comment

How to kill an abandoned process in Linux/Unix

I remembered it, then I forgot, then I remembered it, and then I forgot again. In case of a Linux/Unit process hang, I have to figure out ...