git checkout command explained
Introduction In our previous article on working with the git version control system, we explained and familiarized the concept of the HEAD. In this article, we introduce you to the git checkout command and explain how it can be used to restore files to their previous committed states. What is git checkout? The git checkout command takes the HEAD and moves it to a different point in the commit history of your git repository. So, the git checkout command allows us to check out or restore a previous state of the file. We can commit the restored version of the file and save it as the most recent commit or we could revert to the most recent committed version of the file using git checkout. Demonstration: We’ll now demonstrate how we can use the git checkout command to revert to a previous state of a single file in a git repository and also how to restore the checked out file back to its last committed state. Let’s take a look at the state of our repository two commits before the current commit using git diff. [sahil@linuxnix my_first_repo]$ git diff HEAD~2 diff --git a/README.md b/README.md deleted file mode 100644 index ba76a74..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -This is a readme file for my first git repository diff --git a/test.txt b/test.txt index 06ee124..e945f40 100644 --- a/test.txt +++ b/test.txt...
Read More