![]() ![]() This is the one that can really make you lose work, because it modifies your work tree. The other is simply moving a branch from one place to another, and keeping index/work tree in sync. don't change the branch but get rid of all local changes. One primary use is blowing away your work but not switching commits: git reset -hard means git reset -hard HEAD, i.e. This is the easiest to understand, probably. hard makes everything match the commit you've reset to. Remember, the index is git's "staging area" - it's where things go when you say git add in preparation to commit. There are four main options to control what happens to your work tree and index during the reset. resets the current directory to its state in HEAD, and a simple git reset resets everything to its state in HEAD. checkout, diff, log, though the exact semantics vary), so it shouldn't be too surprising.įor example, git reset other-branch path/to/foo resets everything in path/to/foo to its state in other-branch, git reset. This is a common pattern across git commands (e.g. If the paths aren't provided, the entire tree is reset, and if the commit isn't provided, it's taken to be HEAD (the current commit). Paraphrasing the man page, most common usage is of the form git reset, which will reset the given paths to their state from the given commit. Git permanently deletes such commits after 30 days, but until then you can recover C by pointing a branch at it again ( git checkout C git branch ). It's still in the repo, and you can find it by looking at git reflog show HEAD or git reflog show master, but it's not actually accessible from any branch anymore. In the toy example above, we lost commit C. Git reset commit can cause you to (sort of) lose commits. ![]() It can really be used for a wide variety of things the common thread is that all of them involve resetting the branch, index, and/or work tree to point to/match a given commit. I cover many of the main use cases for git reset within my descriptions of the various options in the next section. The rest is just details of what happens to your index and work tree. Remember, reset doesn't make commits, it just updates a branch (which is a pointer to a commit) to point to a different commit. If you make a new commit D at this point, you'll get this, which is probably not what you want: - A - B - C (master) HEAD, work tree, index all match B, but the master branch was left behind at C. You've ended up in a detached HEAD state. If you'd run git checkout B, you'd get this: - A - B (HEAD) - C (master) More concretely, if your master branch (currently checked out) is like this: - A - B - C (HEAD, master)Īnd you realize you want master to point to B, not C, you will use git reset B to move it there: - A - B (HEAD, master) # - C is still here, but there's no branch pointing to it anymoreĭigression: This is different from a checkout. In general, git reset's function is to take the current branch and reset it to point somewhere else, and possibly bring the index and work tree along. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |