How do I revert a Git repository to a previous commit?
Stack How?
Stackorigin – The Community of Question and Answers Latest Articles
Read More About Python List Comprehension with examples
Python List Comprehension: Python List comprehension provides a much more short syntax for creating a new list based on the values of an existing list. Advantages of List Comprehension in Python: Time Efficient than loop Space Efficient than loop Needs ...
Do not accept an offer letter from companies.
Do not accept an offer letter from companies without verifying the following points. Designation Salary Details & CTC Distribution Leave Policies Working Hours & Days Medical Coverage/Insurance Probation Period Notice Period Benefits and Perks Bonus F&F Policy
How to call API using Ajax
AJAX stands for Asynchronous JavaScript and XML and its used for to make calls to the server to fetch some data. In this article, we will learn how to implement a simple API call using AJAX technology. How to use GET ...
To revert to a commit that’s older than the most recent commit:
You can do this by the following two commands:
It will remove your previous Git commit.
If you want to keep your changes, you can also use:
Then it will save your changes.
Revert back without keeping the changes:
Revert back with keeping the changes:
Explanation: using
git reset
, you can reset to a specific state. It’s common using it with a commit hash as you see above.But as you see the difference is using the two flags
--soft
and--hard
, by defaultgit reset
using--soft
flag, but it’s a good practice always using the flag, I explain each flag:–soft
The default flag as explained, not need to provide it, does not change the working tree, but it adds all changed files ready to commit, so you go back to the commit status which changes to files get unstaged.
–hard
Be careful with this flag. It resets the working tree and all changes to tracked files and all will be gone!
How do I revert a Git repository to a previous commit:
What do you think would happen if we did a git revert on the third commit with ID 4945db2? This was the git commit that added the charlie.html file.
The git revert command will undo only the changes associated with a specific commit. In this git revert example, the third commit added the charlie.html file. When we revert said Git commit, the only file removed from our repository is charlie.html.