![]() For hard, we do both of those steps but in addition, we also reset the working area. ![]() For mixed, we do that as well as reset the staging area. If we git reset to a commit, we move the head and the current branch for soft. > Nina Zakharenko: So a little bit of a cheat sheet here. > Nina Zakharenko: And this is the result of our git reset hard. This operation can't be undone, so proceed with caution. If your file in the working area had any changes, you just lost them. Lastly, it also copies it to the working area. Next, it copies the file from commit B to our staging area. > Nina Zakharenko: Now, git reset hard, it does the same steps from soft and from mixed, but now it adds another one. > Nina Zakharenko: So after a git reset mixed, it looks like this. > Nina Zakharenko: Mixed is the default, you can also consider it the unstaged commands. In this case, it's B, to the staging area. > Nina Zakharenko: And then, it copies the file from the commit that head is pointing to. > Nina Zakharenko: The next step, git reset -mixed, the default. If you make commits after you do a git reset soft, that A is gone. > Nina Zakharenko: Or make a branch off it, or recover it some other way. > Speaker 2: So you'd have to move your head back there, in order for it to still. > Nina Zakharenko: It's still there, but you can consider it dangling, you can consider it possibly a dangling commit at this point, because. > Speaker 2: So is A still there, in case you wanna go back to it? > Nina Zakharenko: And that's our result, now. Now our head just points to the previous commit. Git reset -soft, and here I'm specifying HEAD~, which means the previous commit. Soft tends not to be used very frequently but this is just the first step of git reset. Soft, mixed, which is the default, and hard. Diagrams that very clearly represent what's going on when we do a git reset. This is a lot to take in, and I'm seeing some blank stares, but I have diagrams. > Nina Zakharenko: But if you pass a file path, it's not going to move the head pointer, it's just going to modify the files. Now for commits, git reset moves the head pointer, and it will optionally modify files. Whatever it was pointing to before is going to be different. Git reset moves the head and it'll move the branch reference, meaning your branch is now modified. > Nina Zakharenko: But the branch stays where it was. > Nina Zakharenko: A big difference between git reset and git checkout is, git checkout will move the head, And once you figure that out, you’re never gonna be afraid to use it again. > Nina Zakharenko: But we’re gonna really understand what git reset does. You had some unsaved changes, and now you wanna swear off git forever. You weren't sure what you were running, and all of a sudden, you overwrote your changes. > Nina Zakharenko: Understanding reset is really important, because all it takes is one git reset -hard. But by default, git performs a git reset -mixed. Depending on the arguments, the actions are different. But you have to know that it's another one of those commands that performs different actions, depending on if it's run with a path or without a path. But understanding reset will really supercharge your workflow. I find that people tend to Google, how do I undo the last command, and just copy and paste the answer from stack overflow. And we'll see now that, if I run and get status, my working area is clean. Now, I actually run it with git clean -d -f, and it goes ahead and deletes those two files, the file and the directory. That would show me, I'm sorry, if I don't pass the -f flag, it would show me what files and directories it would delete. If I actually wanna do it, I do, git clean -d and -dry-run. > Nina Zakharenko: So Git Clean -dry-run, it's telling me that it would remove a -note.txt, that's a file on my working area that's not committed. I can also specify -d to clean both files and directories. And then I can do the -f flag to actually do the deletion. I can use the -dry-run flag, and that will list what's going to be deleted. If I run Git Clean with no arguments, it gives me a warning. But this operation is a little bit friendlier. It clears your working area by deleting untracked files. > Nina Zakharenko: Git Clean does that for you. Someone was asking earlier, I had a student question, how do I clean up my working area?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |