![]() ![]() A file level checkout will change the file's contents to those of the specific commit.Ī revert is an operation that takes a specified commit and creates a new commit which inverses the specified commit. The git checkout command can be used in a commit, or file level scope. This is an update to the "Commit History" tree. The HEAD ref and main branch ref currently point to commit d. This example demonstrates a sequence of commits on the main branch. To demonstrate this consider the following example. Keep these mechanisms in mind as you read through this article.Ī checkout is an operation that moves the HEAD ref pointer to a specified commit. We explore the three trees in depth on the git reset page. ![]() These components are sometimes known as "The three trees" of Git. It helps to think about each command in terms of their effect on the three state management mechanisms of a Git repository: the working directory, the staged snapshot, and the commit history. Hopefully, you’ll walk away with the confidence to navigate your repository using any of these commands. In this article, we’ll compare the most common configurations of git reset, git checkout, and git revert. They all let you undo some kind of change in your repository, and the first two commands can be used to manipulate either commits or individual files.īecause they’re so similar, it’s very easy to mix up which command should be used in any given development scenario. We'll take a look at how to use "git revert" in the next video.The git reset, git checkout, and git revert commands are some of the most useful tools in your Git toolbox. This is great, but what if you make a change and then make multiple commits before you realize that that change broke something? "git reset" isn't helpful, because you want to keep all of the changes since the bad commit. Now, "git status" shows a clean working directory, and "git log -oneline" confirms that we are back to the "Installed Views 3.8" commit. Now, you'll see that "HEAD is now at 269bec4 Installed Views 3.8", so our repo is back to the way it was before we updated Views. If, at this point, you realize that the 3.10 version of Views caused an issue and you'd like to reset those commits and associated files so that it'll be as though you never installed the update, you can do that by specifying the commit you would like to reset to. Now, "git status" shows a clean working directory, and "git log -oneline" shows the two commits. ![]() git commit -m "Added missing Views 3.10 file".Now a "git status" show us that we missed the unstaged file. I'll start out by updating Views to 3.10 and committing it. Now, we'll take a look at using the "git reset -hard" command, and passing a hash to reset multiple commits including associated files. Resetting Multiple Commits and Associated Files Now "git status" shows that we have a clean working directory and "git log -oneline" shows that we are at the "Installed Views 3.8" commit. rm -rf sites/all/modules/contrib/views/modules/field/views_handler_filter_field_list_boolean.inc.So, now, just like I did then, I'll delete the untracked file with the rm command. Now, you'll see that "HEAD is now at 269bec4 Installed Views 3.8", so we're still at the same commit, and "git status" will show us that the only files not committed are the untracked files, just like when we ran "git checkout sites/all/modules/contrib/views" to checkout the entire views directory in the earlier video. If you'd like to reset your uncommitted changes back to the last commit, you can use "git reset -hard" to do so. Reseting Staged Files to the Latest Committed State The first way I'll show you to use the "git reset -hard" command imitates the way we used "git checkout" in the video Reverting to the Committed Versions of Files where we checked out the entire views directory. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |