Git Revert: git revert <SHA-of-commit-to-revert>
Suppose we added a piece of code in given commit and we want to remove it from commit. Git revert comes for rescue.If Git reverts given commit , then Git will make a new commit where that piece of code is deleted. It also works the other way where if piece of code were removed in given commit, then reverting that commit will add that content back.
➜ custom_cloned_repo git:(master) git revert 582d67c9b0a9376101a50d02f46ee34e0de69772 [master fecb359] Revert "created css" 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 front.css
Below image shows, a css file is created and committed. Later we find SHA value using "git log" and revert that commit. In reverting that css file is deleted, git does it by creating new commit. 999999999
Git Reset: git reset <--flag/file/sha>
Reverting creates a new commit that reverts or undos a previous commit. Resetting, on the other hand, erases commits. Three flavour of rest command.- Move HEAD : "reset command" moves the branch that HEAD is pointing to. It means if HEAD is set to the master branch (i.e. We are currently on the master branch), running
git reset 9e5e6a4 will start by making master point to 9e5e6a4.➜ custom_cloned_repo git:(master) git reset --soft Head~
- Updating the Index (--mixed) : This is default flag associated with reset, if noting is provided.
reset with --mixed will bring Head and Index at same commit level.➜ custom_cloned_repo git:(master) git reset HEAD~ OR ➜ custom_cloned_repo git:(master) git reset --mixed Head~
- Updating the Working Directory (--hard): Think for a sec before using flag "--hard". This flag will overwrite working directory file with the commit to be reset(Head~ in above example).
After executing --mixed command, master and test branch were on different commit, see first part of below diagram.
Now we checkout test and use "--hard" flag, css file is deleted from working directory of test branch because Head~ refers to.
Git checkout <branch> vs git reset --hard <branch>
Running git checkout [branch] is pretty similar to running git reset --hard [branch] in that it updates all three trees(Head, Index and working directory) for you to look like [branch], however there are two important differences.First, unlike reset --hard, checkout is working-directory safe; it will check to make sure it’s not blowing away files that have changes to them. Actually, it’s a bit smarter than that — it tries to do a trivial merge in the Working Directory, so all of the files you haven’t changed will be updated.
reset --hard, on the other hand, will simply replace everything across the board without checking.
The second important difference is how checkout updates HEAD. Whereas reset will move the branch that HEAD points to, checkout will move HEAD itself to point to another branch.
Below image from git-scm.com. Consider master and develop branches which point at different commits and we’re currently on develop (so HEAD points to it). If we run git reset master, develop itself will now point to the same commit that master does. If we instead run git checkout master, develop does not move, HEAD itself does. HEAD will now point to master.
|
Ancestry References:
To tell Git about the commit that's one before the current commit or two before the current commit. These are relative references, in git we use special special characters called "Ancestry References" to refer relative references. Those characters are:^ – indicates the parent commit
~ – indicates the first parent commit
The parent commit – the following indicate the parent commit of the current commit
- HEAD^
- HEAD~
- HEAD~1
The grandparent commit – the following indicate the grandparent commit of the current commit
- HEAD^^
- HEAD~2
The great-grandparent commit – the following indicate the great-grandparent commit of the current commit
- HEAD^^^
- HEAD~3
The main difference between the ^ and the ~ is evident when a commit is created from a merge. A merge commit has two parents. With a merge commit, the ^ reference is used to indicate the first parent of the commit while ^2 indicates the second parent. The first parent is the branch you were on when you ran git merge while the second parent is the branch that was merged in.
Reference: https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified
Tags:
git
If you are a good looking and want to grow yourself with good wealth in the term of money work as a Female Escorts Job in Delhi, then you are welcome in our Call Girls job in Delhi agency, to start your work as Female escorts. We are now hiring a good and decent Charming Call Girls for Escorts Girl Job in Delhi,
ReplyDeletePart time or Full time Escorts Job in Delhi, first of all u have to send your profile. We are the oldest and genuine Female escort’s agency who provide and hiring girls for Female Escorts Job in Delhi in all over India and we never disclose your identity and your protection is our responsibility so just go ahead and join us for the splendid time work as a Call Girls job in Delhi. we have also Escorts Girl Job in Delhi openings.
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletegia ve may bay di my
mua vé máy bay từ mỹ về việt nam hãng eva
từ nhật về việt nam có bị cách ly không
bay từ đức về việt nam mấy tiếng
chuyến bay từ canada về việt nam
mua ve may bay tu han quoc ve viet nam
khách sạn cách ly ở nha trang
chuyen bay danh cho chuyen gia