Advanced Git by By Chris Belanger & By Chris Belanger and Jawwad Ahmad & By Jawwad Ahmad

Advanced Git by By Chris Belanger & By Chris Belanger and Jawwad Ahmad & By Jawwad Ahmad

Author:By Chris Belanger & By Chris Belanger and Jawwad Ahmad & By Jawwad Ahmad
Language: eng
Format: epub
Publisher: Ray Wenderlich


You’ve seen that checkout simply moves HEAD to a particular commit. reset is similar, but it also takes care of moving the branch’s label to the same commit instead of leaving the branch label where it was. reset, in effect, returns your working environment — including your branch label — to the state a particular commit represents.

Consider again the example above, with a simple branch, mybranch, off of main:

This time, you execute a reset command with a target commit of b1:

Both HEAD and mybranch have now moved back to b1. This means you’ve effectively discarded the original tip commits of the mybranch branch, and stepped back to the b1 commit.

But what happens to the tip commit that’s now separated from the b1 label?

From Git’s perspective, it doesn’t exist anymore. Git will collect it with its regular garbage collection cycle, and any commits you make on mybranch will now stem from the b1 commit as their ancestor.

In this way, reset is quite useful when you’re trying to “roll back” commits you’ve made, to get to an earlier point in your repository history. reset has a lot of different use cases for it, and with it several options to learn about that change its behavior.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.