![]() Option 1: Discard All of the Recent Commit’s Changes There are two options to do this both options reset the Git repository’s branch but one discards all of the changes while the other leaves the changes staged. Now we're set to add all of the files and make one commit instead of cluttering our log with two.If you’ve ever wanted to undo the most recent local commits in Git before pushing your changes to production, you’ve come to the right place. Now, you'll see a list of the unstaged changes after the reset, "git log -oneline" indicates that our last commit was when we installed Views 3.8, and "git status" shows all of the new and modified files that came with the update to Views 3.10. If you'd like to reset those commits so that you can make one clean commit, 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 commit these files in two commits, and then show you how to go back more than one commit. You can even use this to go back multiple commits at once. You'll see a list of unstaged changes after the reset, "git log -oneline" indicates that our last commit was when we installed Views 3.8, and "git status" shows all of the new and modified files that came with the update to Views 3.10. To do that we'll use the "git reset" command and pass the hash of the commit that we would like to reset to. Now that we know the commit is only on our machine, let's say we realized that Views 3.10 conflicts with some custom code we've written, and want to revert back to the old version until we can update our custom code. Instead, you should use the "git revert" command that we'll discuss in the video Reverting One or More Specific Commits with "git revert". This is very important! Once you've pushed a commit, you generally don't want to reset it with the "git reset" command. Typing "git log -oneline" shows the new commit, while "git status" shows that we haven't yet pushed the commit to the central repo. I'll commit the update to views so that we can reset it. Use this when you want to completely reset changes and history back to a specific commit. This removes the last x commits (back to the hash you choose), and resets changes to files.The other reset command we'll look at is "git reset -hard " (again, defaults to HEAD, which is last committed state).ie: when you realize you weren't done making your changes and committed too early. Use this command when you want to remove the last x commits (back to the hash you choose) but keep changes to files in tact.The default reset command is "git reset " (where defaults to HEAD, which is last committed state).The seven character hash at the beginning of each line in that log is unique to and represents that commit. You can get the hash of the desired commit by typing "git log -oneline". When you use either version, you have the option to pass a commit hash to the command. ![]() ![]() The basic "git reset" and "git reset -hard". You can find the full list in the Git documentation, but I'm just going to show you two at this time. There are a number of options you can pass when using the "git reset" command. We can use the "git reset" command to reset our repo to a specified state. Let's say we've tested the update, and it causes a conflict with another module we're using. Now "git status" will show modified and untracked files. I'll start out by updating the Views module to the latest release. There are two commands that can do that for you "git reset" and "git revert". In the last video we saw how to reset a file or directory to it's last committed state, but what if you make a commit and then need to undo it?Īt some point you will make a commit, and then realize that it broke something, or the code just really wasn't ready to be committed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |