Sometimes other project members need to view the whole log history of the working repository branches. For the specified purpose, the “$ git log” and “$ git reflog” commands can be utilized.
This guide will illustrate how to use the git reflog and elaborate on the difference between the reflog and log.
What is git reflog Command?
“git reflog” is a Git command used when developers are required to track the log history of the Git local commits and exclude any commits that were pruned away from the current local repository. It includes reverting action logs, creating branches, committing changes, and deleting and switching the history log.
Now, let’s move toward the next section to implement the “git reflog” command!
How to Use git reflog?
The “git reflog” command is mainly used when developers need to view the repository’s local commits history, including commit changes, created branches, reverting actions log, switching and removing branches history log, and many more.
Follow the below-provided steps!
Step 1: Open Git Terminal
Search and open the “Git Bash” using the “Startup” menu:
Step 2: Navigate to Git Repository
Move to the Git local repository using the provided command:
Step 3: Create New File
Next, execute the “touch” command to create a new file in the Git repository:
Step 4: Add File
Now, track the newly created file to the staging area by using the “git add” command:
Step 5: Commit Changes
After that, execute the “git commit” command with the “-m” option to commit changes to the Git repository:
Step 6: Check Reference Log History
Finally, check the Git local commit history log of the Git repository using the provided command:
The whole log history is displayed on the terminal, and the highlighted log refers to the recently committed changes:
Now, move toward the next section to view the difference between reflog and log commands.
Git reflog vs. log
The Git “reflog” command is utilized when users directly track the log history of the current working repository branch of the local commits and remove any commits that were pruned away from the repository. This command’s output will display the reverting action logs, creating new branches, committing changes, and removing and switching the history log. In contrast, The “git log” command offers the repository branch’s commit traversal history, including remote repository name, time, and provided credentials.
Conclusion
To use git reflog, first, navigate to the Git local repository and check the log history using the “$ git reflog” command. The “reflog” command is used to view the reverting action logs, create new branches, commit changes, and remove and switch the history log. In contrast, “log” commands show all of the commit changes at once. This guide illustrated how to use the git reflog and discussed the reflog vs. log.