Reputation: 2061
git-revert documentation says:
git revert -n master~5..master~2
Revert the changes done by commits from the fifth
last commit in master (included) to the third last commit in master (included)
But my observation shows something different.
After the call:
git revert HEAD~1..HEAD
The last commit is removed instead of the previous one.
So I'd say that:
git revert -n master~5..master~2
reverts the changes done by commits from the fourth last commit in master (included) to the second
last commit in master (included).
Other example: git revert HEAD
reverts last commit - this is ok
But git revert HEAD..
says that given list is empty - I'd expect that it reverts last commit as well since documentation says that left boundary is included.
Am I right?
Upvotes: 2
Views: 368
Reputation: 142094
Let's make some order in your question.
Before we start lets have some terminology
Terminology
HEAD = Current commit
../ ... = Commit range (from ... to)
revert = Undo the given change
git revert -n master~5..master~2
Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included)
You are using range. The range is from...to, in your case from 5 to 2 (not including).
git revert HEAD~1..HEAD
The last commit is removed instead of the previous one.
You are telling git this: Please revert the content in the range of the previous commit up to the last one
so its undo the changes from the previous commit [not included] HEAD~1
up to the current commit HEAD
Other example:
git revert HEAD
reverts last commit - this is ok
In this case you are giving a single SHA-1 (HEAD
) so its reverting the given commit. Its the same as reverting any other commit in the history.
# revert commit XYZ
git revert XYX
# revert the current commit (git will extract the HEAD SHA-1)
# (Again read the linked post above to fully understand what is HEAD)
git revert HEAD
But
git revert HEAD..
says that given list is empty
As explained above ..
stands for a range. You supplied the only one side of the list (missing from/ to depends how you look on it)
If we will go back to this: git revert -n master~5..master~2
what that happening behind the scenes is something like this:
for (index=first SHA-1 to index= last SHA-1)
git revert SHA-1
git revert -n master~5..master~2 ->
git revert -master~5
git revert -master~4
git revert -master~3
Upvotes: 1