title
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits

description
In this video we will look at some common mistakes in Git and how we can fix these mistakes. Specifically we will cover how to discard changes since your last commit, amending commits, cherry-picking hashes, resetting to a specific commit, and reverting to a specific commit. ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Git

detail
{'title': 'Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits', 'heatmap': [{'end': 415.303, 'start': 382.691, 'weight': 0.813}, {'end': 595.809, 'start': 577.191, 'weight': 0.716}, {'end': 672.861, 'start': 651.645, 'weight': 0.765}, {'end': 1014.771, 'start': 981.432, 'weight': 1}, {'end': 1058.621, 'start': 1029.255, 'weight': 0.716}, {'end': 1174.701, 'start': 1149.209, 'weight': 0.773}], 'summary': "Learn to undo mistakes and manage changes in git, including fixing incorrect commit messages, moving commits to feature branches, and using 'git revert' to maintain uncorrupted history and facilitate collaboration.", 'chapters': [{'end': 41.701, 'segs': [{'end': 41.701, 'src': 'embed', 'start': 0.229, 'weight': 0, 'content': [{'end': 1.25, 'text': "Hey, how's it going everybody?", 'start': 0.229, 'duration': 1.021}, {'end': 11.4, 'text': "In this video we're going to be looking at a few common scenarios in Git where you can find yourself needing to undo some mistakes or even roll back some bad commits.", 'start': 1.751, 'duration': 9.649}, {'end': 16.024, 'text': 'Now, some of these commands will change the Git history and some will not.', 'start': 12.261, 'duration': 3.763}, {'end': 19.469, 'text': "And we're going to take a look at exactly what that means here in a second.", 'start': 16.486, 'duration': 2.983}, {'end': 29.154, 'text': "Now this will be a slightly more advanced Git walkthrough and we're going to assume that you already know the basic command line functionality of Git.", 'start': 20.009, 'duration': 9.145}, {'end': 36.899, 'text': "If you aren't familiar with basic Git commands or how Git works, I do have a video on getting started with Git in the command line,", 'start': 30.015, 'duration': 6.884}, {'end': 38.82, 'text': 'if you would like to watch that video first.', 'start': 36.899, 'duration': 1.921}, {'end': 41.701, 'text': "But with that said, let's go ahead and get started.", 'start': 39.46, 'duration': 2.241}], 'summary': 'Advanced git tutorial on undoing mistakes and rolling back bad commits.', 'duration': 41.472, 'max_score': 0.229, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk229.jpg'}], 'start': 0.229, 'title': 'Undoing mistakes in git', 'summary': 'Discusses common scenarios in git where you may need to undo mistakes or roll back bad commits, distinguishing commands that change git history from those that do not, in a slightly advanced walkthrough.', 'chapters': [{'end': 41.701, 'start': 0.229, 'title': 'Undoing mistakes in git', 'summary': 'Discusses common scenarios in git where you may need to undo mistakes or roll back bad commits, distinguishing commands that change git history from those that do not, in a slightly advanced walkthrough.', 'duration': 41.472, 'highlights': ['The chapter covers common scenarios in Git where you may need to undo some mistakes or roll back bad commits.', 'It distinguishes between commands that change Git history and those that do not.', 'The walkthrough assumes familiarity with basic command line functionality of Git.']}], 'duration': 41.472, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk229.jpg', 'highlights': ['The chapter covers common scenarios in Git where you may need to undo some mistakes or roll back bad commits.', 'It distinguishes between commands that change Git history and those that do not.', 'The walkthrough assumes familiarity with basic command line functionality of Git.']}, {'end': 283.944, 'segs': [{'end': 114.186, 'src': 'embed', 'start': 64.733, 'weight': 1, 'content': [{'end': 70.675, 'text': 'So now if I run a git status, you can see that currently our working directory is clean.', 'start': 64.733, 'duration': 5.942}, {'end': 75.677, 'text': "If I do a git log, then you can see that we've only had one commit so far.", 'start': 71.176, 'duration': 4.501}, {'end': 77.078, 'text': "It's just the initial commit.", 'start': 75.777, 'duration': 1.301}, {'end': 85.801, 'text': 'And also if I run a git branch, you can see that we have another branch here called subtract feature.', 'start': 77.878, 'duration': 7.923}, {'end': 92.325, 'text': 'So both the subtract feature branch and the master branch are currently exactly the same.', 'start': 86.762, 'duration': 5.563}, {'end': 94.827, 'text': 'They both only have that one initial commit.', 'start': 92.385, 'duration': 2.442}, {'end': 98.471, 'text': "But for now, we're not going to bother with the subtract feature branch.", 'start': 95.748, 'duration': 2.723}, {'end': 101.174, 'text': "We'll take a look at that here in a little bit.", 'start': 98.491, 'duration': 2.683}, {'end': 105.538, 'text': "So let's look at our first example of a mistake that you might want to undo.", 'start': 101.875, 'duration': 3.663}, {'end': 109.623, 'text': "So first, we're going to say that we've made changes to a file.", 'start': 106.379, 'duration': 3.244}, {'end': 114.186, 'text': "And after a while, we realize that we don't want any of the changes that we've made.", 'start': 110.243, 'duration': 3.943}], 'summary': 'Working directory is clean, one commit, and two branches with one initial commit each. exploring examples of undoing changes.', 'duration': 49.453, 'max_score': 64.733, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk64733.jpg'}, {'end': 188.946, 'src': 'embed', 'start': 164.209, 'weight': 0, 'content': [{'end': 173.694, 'text': 'and if I hit enter there now, if I do a git status, you can see that our working directory is clean, and if I do a git diff,', 'start': 164.209, 'duration': 9.485}, {'end': 175.596, 'text': "you can see that we don't have any changes.", 'start': 173.694, 'duration': 1.902}, {'end': 179.038, 'text': 'and if I go over here to the file and this reloads over here,', 'start': 175.596, 'duration': 3.442}, {'end': 184.061, 'text': 'you can see that we are back to the way that things were after we made our initial commit.', 'start': 179.038, 'duration': 5.023}, {'end': 188.946, 'text': "So now let's actually make some changes to our file that we do want to commit to our repository.", 'start': 184.841, 'duration': 4.105}], 'summary': 'Demonstrated clean working directory and no changes in git status; reset to initial commit state.', 'duration': 24.737, 'max_score': 164.209, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk164209.jpg'}, {'end': 256.154, 'src': 'embed', 'start': 207.702, 'weight': 3, 'content': [{'end': 210.123, 'text': "And I'm going to add that to the staging area.", 'start': 207.702, 'duration': 2.421}, {'end': 215.325, 'text': 'And now if I do another git status, you can see that that file is ready to be committed.', 'start': 210.643, 'duration': 4.682}, {'end': 219.267, 'text': "So now I'm going to go ahead and commit this file.", 'start': 215.845, 'duration': 3.422}, {'end': 225.669, 'text': "But let's say that we make a git commit and accidentally mess up our commit message.", 'start': 220.247, 'duration': 5.422}, {'end': 234.776, 'text': "So I'm going to say that we completed the multiply function, which is wrong because we completed the subtract function.", 'start': 225.749, 'duration': 9.027}, {'end': 238.379, 'text': "so I'm gonna go ahead and commit that with the bad commit message.", 'start': 234.776, 'duration': 3.603}, {'end': 245.064, 'text': "so now, if I do a git log, you can see that we've made the commit, but the message is wrong.", 'start': 238.379, 'duration': 6.685}, {'end': 250.489, 'text': 'so how do we modify this message without doing another commit?', 'start': 245.064, 'duration': 5.425}, {'end': 256.154, 'text': 'well, to do that we can just do another commit with the dash dash amend option.', 'start': 250.489, 'duration': 5.665}], 'summary': 'Demonstrates using git to stage, commit, and amend commit messages.', 'duration': 48.452, 'max_score': 207.702, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk207702.jpg'}], 'start': 41.721, 'title': 'Managing git changes and commit messages', 'summary': "Demonstrates how to use 'git checkout' to discard changes, add files to the staging area, and amend commit messages in a git repository, with a focus on fixing incorrect commit messages and modifying the last commit message. it also highlights the presence of the initial commit and the 'subtract feature' branch.", 'chapters': [{'end': 138.562, 'start': 41.721, 'title': 'Undoing changes in git', 'summary': "Demonstrates how to undo changes in a git repository, including checking the repository status, viewing commit history, and resetting changes, while also highlighting the presence of the initial commit and the 'subtract feature' branch.", 'duration': 96.841, 'highlights': ["The .git directory indicates that we are within a Git repository, and the working directory is clean after checking with 'git status'.", 'The git log shows that there has been only one initial commit so far.', "The existence of the 'subtract feature' branch, which is currently identical to the master branch with only the initial commit, is observed when running 'git branch'.", 'An example of undoing changes in a file is discussed, emphasizing the need to revert to the previous state when realizing that the changes made are undesirable.']}, {'end': 283.944, 'start': 139.605, 'title': 'Managing git changes and commit messages', 'summary': "Demonstrates how to use 'git checkout' to discard changes, add files to the staging area, and amend commit messages in a git repository, with a focus on fixing incorrect commit messages and modifying the last commit message.", 'duration': 144.339, 'highlights': ["The chapter illustrates using 'git checkout' to discard changes and restore the file to its original state, resulting in a clean working directory and no changes in the git diff.", "It explains the process of adding modified files to the staging area using 'git add', preparing them for committing to the repository.", "The transcript details the method of amending a commit message using 'git commit --amend', allowing the user to correct the last commit message without creating additional commits.", "It showcases how to identify the incorrect commit message using 'git log' and then modify it using 'git commit --amend -m' to accurately reflect the changes made in the commit."]}], 'duration': 242.223, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk41721.jpg', 'highlights': ['The .git directory indicates a Git repository, with a clean working directory.', "The 'subtract feature' branch is observed, identical to the master branch with only the initial commit.", "Using 'git checkout' to discard changes results in a clean working directory and no changes in git diff.", "Amending a commit message with 'git commit --amend' corrects the last commit message without additional commits.", "Identifying and modifying incorrect commit messages using 'git log' and 'git commit --amend -m'.", 'Undoing changes in a file emphasizes the need to revert to the previous state when changes are undesirable.', 'The git log shows only one initial commit in the repository.', "Adding modified files to the staging area using 'git add' prepares them for committing."]}, {'end': 501.426, 'segs': [{'end': 310.921, 'src': 'embed', 'start': 284.564, 'weight': 0, 'content': [{'end': 291.527, 'text': 'Now, I do need to point out that this unique hash here is different than it was before we changed the commit message.', 'start': 284.564, 'duration': 6.963}, {'end': 298.31, 'text': "Now, that's because the commit message is part of the commit and changing it will also change the hash.", 'start': 292.007, 'duration': 6.303}, {'end': 303.499, 'text': 'And when the hash changes, that means that it changed the Git history.', 'start': 298.997, 'duration': 4.502}, {'end': 310.921, 'text': "So we only want to ever change the Git history when we are the only ones who have had access to the changes that we've made.", 'start': 304.339, 'duration': 6.582}], 'summary': 'Changing commit message alters hash, affects git history', 'duration': 26.357, 'max_score': 284.564, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk284564.jpg'}, {'end': 352.25, 'src': 'embed', 'start': 322.265, 'weight': 2, 'content': [{'end': 328.09, 'text': "So later in this video, we're going to look at some ways in which we can make corrections without changing the git history.", 'start': 322.265, 'duration': 5.825}, {'end': 334.916, 'text': "But as long as we're the only ones who have seen our changes, then changing the history isn't necessarily a bad thing,", 'start': 328.491, 'duration': 6.425}, {'end': 336.858, 'text': 'and it also makes for cleaner commits.', 'start': 334.916, 'duration': 1.942}, {'end': 345.465, 'text': "So in the case of a bad commit message, this is likely something that you'll notice right away and can fix it right on the spot like we just did.", 'start': 337.819, 'duration': 7.646}, {'end': 352.25, 'text': 'Now kind of a similar scenario is that, instead of accidentally committing the wrong message,', 'start': 346.366, 'duration': 5.884}], 'summary': 'Ways to make corrections without changing git history, improving commit messages.', 'duration': 29.985, 'max_score': 322.265, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk322265.jpg'}, {'end': 382.47, 'src': 'embed', 'start': 356.193, 'weight': 1, 'content': [{'end': 362.858, 'text': "So in this example, let's say that I meant to create a gitignore file and I wanted to add it to that last commit.", 'start': 356.193, 'duration': 6.665}, {'end': 365.84, 'text': "So I'm going to create a .", 'start': 363.258, 'duration': 2.582}, {'end': 375.826, 'text': 'gitignore file here, and now let me go ahead and run a git status, and also let me add that to the staging area.', 'start': 365.84, 'duration': 9.986}, {'end': 377.948, 'text': "So I'll do the git add .", 'start': 375.846, 'duration': 2.102}, {'end': 382.47, 'text': "gitignore So now it's in our staging area, but we don't want to make a new commit.", 'start': 377.948, 'duration': 4.522}], 'summary': 'Creating and staging a .gitignore file for the last commit.', 'duration': 26.277, 'max_score': 356.193, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk356193.jpg'}, {'end': 415.303, 'src': 'heatmap', 'start': 382.691, 'weight': 0.813, 'content': [{'end': 387.894, 'text': "So for this example, we're saying that we wanted that to be a part of the last commit.", 'start': 382.691, 'duration': 5.203}, {'end': 396.399, 'text': "So again, we're just going to do the git commit dash dash amend like we did before, but this time it's going to do it with a file.", 'start': 388.314, 'duration': 8.085}, {'end': 404.043, 'text': "So if I hit enter here, now it's going to bring up this interactive editor where we can change the git commit message if we want.", 'start': 396.799, 'duration': 7.244}, {'end': 409.586, 'text': 'Now notice here that this is the same git commit message from our previous commit.', 'start': 404.483, 'duration': 5.103}, {'end': 415.303, 'text': "Now we don't want to change the message in this case, so I'm just going to save and close out.", 'start': 410.12, 'duration': 5.183}], 'summary': "Using 'git commit --amend' to modify the last commit message with a file.", 'duration': 32.612, 'max_score': 382.691, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk382691.jpg'}, {'end': 457.097, 'src': 'embed', 'start': 432.734, 'weight': 3, 'content': [{'end': 441.802, 'text': 'And you can see here that the gitignore file is now part of the last commit where we completed the subtract function.', 'start': 432.734, 'duration': 9.068}, {'end': 447.568, 'text': 'Now once again, just to point out, this unique hash is now different.', 'start': 442.303, 'duration': 5.265}, {'end': 450.33, 'text': 'So we once again changed the git history.', 'start': 447.728, 'duration': 2.602}, {'end': 457.097, 'text': "So just one more time, just to remind you, only do this type of thing if you haven't pushed your changes yet to other people.", 'start': 450.891, 'duration': 6.206}], 'summary': 'Gitignore file included in last commit with changed unique hash, emphasizing caution in altering git history.', 'duration': 24.363, 'max_score': 432.734, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk432734.jpg'}, {'end': 510.033, 'src': 'embed', 'start': 480.709, 'weight': 4, 'content': [{'end': 486.013, 'text': 'Now this is a fairly common mistake to commit to the wrong branch, because when you switch back and forth,', 'start': 480.709, 'duration': 5.304}, {'end': 492.719, 'text': 'sometimes you just forget exactly where you are and end up committing to the wrong branch by accident.', 'start': 486.013, 'duration': 6.706}, {'end': 498.584, 'text': 'So how do we move this commit right here, this 1B818,?', 'start': 493.239, 'duration': 5.345}, {'end': 501.426, 'text': 'how do we move that commit to our feature branch?', 'start': 498.584, 'duration': 2.842}, {'end': 510.033, 'text': 'Now, to be clear here, exactly what we want to do is our goal is to move this commit to our subtract feature branch,', 'start': 501.866, 'duration': 8.167}], 'summary': 'Common mistake: committing to wrong branch. need to move commit 1b818 to feature branch.', 'duration': 29.324, 'max_score': 480.709, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk480709.jpg'}], 'start': 284.564, 'title': 'Git commit and branching', 'summary': 'Covers the impact of changing commit messages on git history, emphasizing the need to avoid altering history after pushing changes. it also discusses amending commits and moving to a feature branch, highlighting potential risks and solutions.', 'chapters': [{'end': 355.733, 'start': 284.564, 'title': 'Git history and commit changes', 'summary': 'Explains the impact of changing commit messages on git history, emphasizing the need to avoid changing history after pushing changes for others to see and pull from, but also highlighting scenarios where changing history can be beneficial, such as for cleaner commits and immediate corrections.', 'duration': 71.169, 'highlights': ['Changing commit messages alters the unique hash and Git history, and should be avoided after pushing changes for others to see and pull from.', 'Making corrections without changing Git history will be discussed later in the video.', 'Changing the history can be acceptable if only the person who made the changes has seen them, leading to cleaner commits and immediate corrections.']}, {'end': 501.426, 'start': 356.193, 'title': 'Amending git commits and moving to feature branch', 'summary': "Discusses amending the last commit by adding a gitignore file, showing the process of using 'git commit --amend' and moving a commit to a feature branch, highlighting the potential risk of committing to the wrong branch and the solution for moving a commit to the correct branch.", 'duration': 145.233, 'highlights': ["The gitignore file is added to the last commit using 'git add .gitignore', and the commit is amended with the file using 'git commit --amend', preserving the previous commit message.", "The process of using 'git log --stat' is demonstrated to show the files changed within the commit, displaying the gitignore file as part of the last commit for the completed subtract function.", "The potential risk of committing to the wrong branch is highlighted, emphasizing the common mistake due to switching back and forth, and the caution to only perform such changes if changes haven't been pushed yet."]}], 'duration': 216.862, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk284564.jpg', 'highlights': ['Changing commit messages alters the unique hash and Git history, and should be avoided after pushing changes for others to see and pull from.', "The gitignore file is added to the last commit using 'git add .gitignore', and the commit is amended with the file using 'git commit --amend', preserving the previous commit message.", 'Changing the history can be acceptable if only the person who made the changes has seen them, leading to cleaner commits and immediate corrections.', "The process of using 'git log --stat' is demonstrated to show the files changed within the commit, displaying the gitignore file as part of the last commit for the completed subtract function.", "The potential risk of committing to the wrong branch is highlighted, emphasizing the common mistake due to switching back and forth, and the caution to only perform such changes if changes haven't been pushed yet.", 'Making corrections without changing Git history will be discussed later in the video.']}, {'end': 937.121, 'segs': [{'end': 577.191, 'src': 'embed', 'start': 526.378, 'weight': 5, 'content': [{'end': 530.879, 'text': 'So in this case, our original is going to be this top commit here.', 'start': 526.378, 'duration': 4.501}, {'end': 535.941, 'text': 'Now cherry pick only creates a new commit based off of that commit.', 'start': 531.44, 'duration': 4.501}, {'end': 539.002, 'text': "It doesn't delete the original after it cherry picks it.", 'start': 535.961, 'duration': 3.041}, {'end': 540.964, 'text': 'So let me clear my screen here.', 'start': 539.562, 'duration': 1.402}, {'end': 552.556, 'text': 'And so the process that you go through to do a get cherry pick is first you want to do a get log because we want to grab the hash of the commit that we want to cherry pick.', 'start': 541.164, 'duration': 11.392}, {'end': 555.219, 'text': "So we don't have to grab the entire hash.", 'start': 553.237, 'duration': 1.982}, {'end': 557.241, 'text': 'Usually six or seven characters is fine.', 'start': 555.339, 'duration': 1.902}, {'end': 567.426, 'text': "so I'm just going to copy this here and now I want to do a git checkout on my subtract feature branch.", 'start': 558.001, 'duration': 9.425}, {'end': 573.969, 'text': "so now I'm going to switch to my subtract feature branch and now from that branch, if I do a git log,", 'start': 567.426, 'duration': 6.543}, {'end': 577.191, 'text': 'you can see that we only have the initial commit.', 'start': 573.969, 'duration': 3.222}], 'summary': "Cherry pick creates new commit, doesn't delete original. get log for hash, checkout to feature branch.", 'duration': 50.813, 'max_score': 526.378, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk526378.jpg'}, {'end': 598.872, 'src': 'heatmap', 'start': 577.191, 'weight': 0.716, 'content': [{'end': 585.52, 'text': "now I'm going to do a git cherry pick and I'm going to paste in the hash that I had copied from the master branch.", 'start': 577.191, 'duration': 8.329}, {'end': 595.809, 'text': 'So now if I hit enter there and now I do a get log, now you can see that we brought that commit for the complete subtract function.', 'start': 586.18, 'duration': 9.629}, {'end': 598.872, 'text': 'We brought that commit over to our subtract feature branch.', 'start': 596.289, 'duration': 2.583}], 'summary': 'Cherry picked commit to subtract feature branch.', 'duration': 21.681, 'max_score': 577.191, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk577191.jpg'}, {'end': 626.176, 'src': 'embed', 'start': 599.432, 'weight': 7, 'content': [{'end': 606.075, 'text': "So now we have that commit on our feature branch, but it still exists on our master branch because cherry pick doesn't delete commits.", 'start': 599.432, 'duration': 6.643}, {'end': 609.657, 'text': "But we don't want that commit on our master branch.", 'start': 607.076, 'duration': 2.581}, {'end': 612.098, 'text': 'We never meant to commit it there to begin with.', 'start': 609.697, 'duration': 2.401}, {'end': 616.8, 'text': "So how do we get rid of it? So to do this, we're going to use a git reset.", 'start': 612.558, 'duration': 4.242}, {'end': 620.762, 'text': "So I'm going to do a git checkout on master.", 'start': 617.16, 'duration': 3.602}, {'end': 626.176, 'text': "And now I'm going to do a git log so that we can see the commits that we have.", 'start': 621.874, 'duration': 4.302}], 'summary': 'Using git reset to remove unwanted commit from master branch', 'duration': 26.744, 'max_score': 599.432, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk599432.jpg'}, {'end': 672.861, 'src': 'heatmap', 'start': 651.645, 'weight': 0.765, 'content': [{'end': 661.292, 'text': "copy that and now I'm going to do a git reset dash, dash soft, and then I'm going to paste in that hash of our initial commit.", 'start': 651.645, 'duration': 9.647}, {'end': 667.917, 'text': 'so now, if I do a git log, you can see that we no longer have that second commit, which is good.', 'start': 661.292, 'duration': 6.625}, {'end': 672.861, 'text': "that's what we wanted, but let's also look at our get status.", 'start': 667.917, 'duration': 4.944}], 'summary': 'Performed git reset --soft to remove second commit, verified by git log and git status.', 'duration': 21.216, 'max_score': 651.645, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk651645.jpg'}, {'end': 702.439, 'src': 'embed', 'start': 673.441, 'weight': 4, 'content': [{'end': 676.362, 'text': 'Now you can see that we have some files in our staging area.', 'start': 673.441, 'duration': 2.921}, {'end': 684.887, 'text': "So soft will reset us back to the commit that we specified, but it will keep our changes that we've made in the staging directory.", 'start': 676.823, 'duration': 8.064}, {'end': 687.269, 'text': "So we didn't lose any of our work.", 'start': 685.508, 'duration': 1.761}, {'end': 691.571, 'text': 'So in this case, our work refers to the addition of the .', 'start': 687.569, 'duration': 4.002}, {'end': 696.414, 'text': 'getignore file and the modifications that we made to the calc.py file.', 'start': 691.571, 'duration': 4.843}, {'end': 699.116, 'text': 'So that is a soft reset.', 'start': 697.074, 'duration': 2.042}, {'end': 702.439, 'text': "Let's look at a mixed reset, which is the default.", 'start': 699.496, 'duration': 2.943}], 'summary': 'Demonstrating soft reset in git, preserving staged changes.', 'duration': 28.998, 'max_score': 673.441, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk673441.jpg'}, {'end': 771.996, 'src': 'embed', 'start': 723.896, 'weight': 2, 'content': [{'end': 730.237, 'text': 'But now if I do a git status, you can see just like git reset soft, it kept the changes.', 'start': 723.896, 'duration': 6.341}, {'end': 734.258, 'text': "However, now these changes aren't in the staging area.", 'start': 731.177, 'duration': 3.081}, {'end': 735.778, 'text': "Now they're in the working directory.", 'start': 734.278, 'duration': 1.5}, {'end': 744.48, 'text': "So it's very similar to git reset soft, but the files are either put in the staging or working directory based on which one you specify.", 'start': 736.298, 'duration': 8.182}, {'end': 748.382, 'text': "But in this example, we really don't want our changes.", 'start': 745.2, 'duration': 3.182}, {'end': 754.205, 'text': 'We really just want to go back to that initial commit and have everything the way that they were.', 'start': 748.922, 'duration': 5.283}, {'end': 759.368, 'text': "So again, let's copy the initial commit hash.", 'start': 755.226, 'duration': 4.142}, {'end': 762.73, 'text': "And this time, we're going to try a get reset hard.", 'start': 759.829, 'duration': 2.901}, {'end': 771.996, 'text': 'So get reset hard is going to make all of our tracked files match the state that they were in at the hash that we specify.', 'start': 763.351, 'duration': 8.645}], 'summary': "Using 'git reset hard' reverts all tracked files to specified hash.", 'duration': 48.1, 'max_score': 723.896, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk723896.jpg'}, {'end': 869.834, 'src': 'embed', 'start': 845.917, 'weight': 0, 'content': [{'end': 853.703, 'text': "gitignore file is gone Now that clean command is a good command to know because it actually comes in handy more often than you'd think.", 'start': 845.917, 'duration': 7.786}, {'end': 864.71, 'text': 'For example, one time I accidentally unzipped a file within my Git repository and it created just a ton of untracked files and subdirectories.', 'start': 854.463, 'duration': 10.247}, {'end': 869.834, 'text': 'And I could have gone through and tried to pick all those out manually and delete all of them.', 'start': 865.211, 'duration': 4.623}], 'summary': 'Gitignore file is missing, clean command useful for removing untracked files and subdirectories.', 'duration': 23.917, 'max_score': 845.917, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk845917.jpg'}, {'end': 937.121, 'src': 'embed', 'start': 908.429, 'weight': 1, 'content': [{'end': 914.873, 'text': 'So you could be out of luck if a lot of time has gone by since you ran that git reset.', 'start': 908.429, 'duration': 6.444}, {'end': 922.758, 'text': "I don't know the exact amount of time, but I think git garbage collects those commits after 30 days or so.", 'start': 915.714, 'duration': 7.044}, {'end': 928.026, 'text': "But git reflog is what we're going to want to use here.", 'start': 924.62, 'duration': 3.406}, {'end': 933.114, 'text': 'So git reflog shows commits in the order of when you last referenced them.', 'start': 928.426, 'duration': 4.688}, {'end': 937.121, 'text': 'So let me run a git reflog here.', 'start': 933.575, 'duration': 3.546}], 'summary': 'Use git reflog to track commits, as git garbage collects after 30 days.', 'duration': 28.692, 'max_score': 908.429, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk908429.jpg'}], 'start': 501.866, 'title': 'Git reset and moving commit to feature branch', 'summary': 'Delves into the process of moving a commit to a feature branch using git cherry pick, resetting the master branch with git reset, and understanding the implications of different git reset options - soft, mixed, and hard - on commit history, staging area, and working directory, emphasizing the importance of grabbing commit hash and the use of git clean to remove untracked files.', 'chapters': [{'end': 620.762, 'start': 501.866, 'title': 'Moving commit to feature branch and resetting master', 'summary': 'Explains the process of moving a commit to a subtract feature branch using git cherry pick and resetting the master branch to its initial state by utilizing git reset, with emphasis on the importance of grabbing the commit hash and the implications of cherry pick not deleting the original commit.', 'duration': 118.896, 'highlights': ['The process involves moving a commit to a feature branch using git cherry pick and resetting the master branch to its initial state using git reset.', 'Emphasis is placed on the importance of grabbing the commit hash and the implication that cherry pick does not delete the original commit.', 'Cherry pick creates a new commit based on the original commit without deleting the original.', 'The importance of grabbing the commit hash is stressed, with six or seven characters usually being sufficient.', 'It is explained that cherry pick does not delete the original commit, leading to the need for a git reset to remove the commit from the master branch.']}, {'end': 937.121, 'start': 621.874, 'title': 'Understanding git reset: soft, mixed, and hard', 'summary': 'Explains the three different types of git reset - soft, mixed, and hard - and their impact on commit history, staging area, and working directory, highlighting how soft reset keeps changes in the staging area, mixed reset keeps changes in the working directory, and hard reset removes all changes, and introduces the use of git clean to remove untracked files.', 'duration': 315.247, 'highlights': ['The chapter explains the three different types of git reset - soft, mixed, and hard - and their impact on commit history, staging area, and working directory, highlighting how soft reset keeps changes in the staging area, mixed reset keeps changes in the working directory, and hard reset removes all changes.', 'The soft reset keeps our changes made in the staging directory, such as the addition of the .gitignore file and the modifications made to the calc.py file.', 'The mixed reset, similar to the soft reset, keeps changes but places them in the working directory instead of the staging area.', 'The hard reset reverts all tracked files back to the state at the specified hash, effectively removing all changes made to the tracked files.', 'Git clean, used to get rid of untracked files, proved to be extremely simple and handy, effectively cleaning the working directory and removing untracked files and directories.', 'Git reflog is recommended for retrieving accidentally deleted changes, as it shows commits in the order of when they were last referenced.']}], 'duration': 435.255, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk501866.jpg', 'highlights': ['Git clean effectively cleans the working directory and removes untracked files and directories', 'Git reflog is recommended for retrieving accidentally deleted changes', 'Hard reset reverts all tracked files back to the state at the specified hash', 'Mixed reset keeps changes but places them in the working directory instead of the staging area', 'Soft reset keeps changes made in the staging directory, such as the addition of the .gitignore file', 'Cherry pick creates a new commit based on the original commit without deleting the original', 'Importance of grabbing the commit hash is stressed, with six or seven characters usually being sufficient', 'Cherry pick does not delete the original commit, leading to the need for a git reset to remove the commit from the master branch', 'Emphasis is placed on the importance of grabbing the commit hash and the implication that cherry pick does not delete the original commit', 'The process involves moving a commit to a feature branch using git cherry pick and resetting the master branch to its initial state using git reset']}, {'end': 1283.079, 'segs': [{'end': 1014.771, 'src': 'heatmap', 'start': 981.432, 'weight': 1, 'content': [{'end': 995.823, 'text': "And I'm going to do a git checkout of that hash and now from here i'm going to run a git log so you can see when i run a git log from this hash that we have our changes back.", 'start': 981.432, 'duration': 14.391}, {'end': 999.985, 'text': 'this is the commit that we reset and got rid of all those changes.', 'start': 995.823, 'duration': 4.162}, {'end': 1003.147, 'text': 'now, right now, we are in a detached head state.', 'start': 999.985, 'duration': 3.162}, {'end': 1006.808, 'text': "now i'm not going to go fully into what this means,", 'start': 1003.147, 'duration': 3.661}, {'end': 1014.771, 'text': "but basically it means that we aren't on a branch And where we currently are it will be trashed at some point in the future.", 'start': 1006.808, 'duration': 7.963}], 'summary': 'Performed git checkout to revert changes, in detached head state.', 'duration': 33.339, 'max_score': 981.432, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk981432.jpg'}, {'end': 1058.621, 'src': 'heatmap', 'start': 1029.255, 'weight': 0.716, 'content': [{'end': 1034.678, 'text': "you can see that currently we're in a detached head state and we'll get garbage collected at some point.", 'start': 1029.255, 'duration': 5.423}, {'end': 1037.981, 'text': 'And now we have our master branch, our subtract feature branch.', 'start': 1035.138, 'duration': 2.843}, {'end': 1040.342, 'text': 'We also have this backup branch.', 'start': 1038.34, 'duration': 2.002}, {'end': 1044.685, 'text': 'So now let me check out the master branch.', 'start': 1040.862, 'duration': 3.823}, {'end': 1052.378, 'text': 'Now from the master branch, if I do a git branch, you can see that we still have our backup branch.', 'start': 1045.834, 'duration': 6.544}, {'end': 1058.621, 'text': "Those changes that we thought that we'd lost, now we have those in this branch here.", 'start': 1052.638, 'duration': 5.983}], 'summary': 'Currently in detached head state, with master, subtract feature, and backup branches. able to recover lost changes.', 'duration': 29.366, 'max_score': 1029.255, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk1029255.jpg'}, {'end': 1141.061, 'src': 'embed', 'start': 1073.809, 'weight': 0, 'content': [{'end': 1082.615, 'text': "Git reflog can really be a lifesaver if you thought that you had lost some critical files that you really didn't mean to delete,", 'start': 1073.809, 'duration': 8.806}, {'end': 1085.517, 'text': 'or that if you accidentally did a reset on something.', 'start': 1082.615, 'duration': 2.902}, {'end': 1089.72, 'text': 'The reflog can really help you out if you know how to use it.', 'start': 1086.498, 'duration': 3.222}, {'end': 1098.728, 'text': "Okay, so in these examples so far, I mentioned that you shouldn't change the git history if other people have pulled those changes already.", 'start': 1090.925, 'duration': 7.803}, {'end': 1106.99, 'text': 'Well, what if you are in a situation where you really need to undo some commits but other people have already pulled those changes?', 'start': 1099.528, 'duration': 7.462}, {'end': 1111.392, 'text': "So in a situation like that, you're going to want to use git revert.", 'start': 1107.571, 'duration': 3.821}, {'end': 1117.177, 'text': 'Revert creates new commits to reverse the effect of some earlier commits.', 'start': 1112.192, 'duration': 4.985}, {'end': 1120.06, 'text': "So this way you don't rewrite any history.", 'start': 1117.898, 'duration': 2.162}, {'end': 1126.386, 'text': "Just to clarify that, it's not going to modify or delete our existing commits that we've made.", 'start': 1120.46, 'duration': 5.926}, {'end': 1134.674, 'text': "It's going to create new commits on top of those that completely undo all of the changes so that our history remains intact.", 'start': 1126.926, 'duration': 7.748}, {'end': 1141.061, 'text': "So just to show an example of this, I'm going to run a git log and you can see that we have our two commits here.", 'start': 1135.214, 'duration': 5.847}], 'summary': 'Use git reflog to recover lost files or undo resets, and git revert to create new commits to reverse earlier changes.', 'duration': 67.252, 'max_score': 1073.809, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk1073809.jpg'}, {'end': 1174.701, 'src': 'heatmap', 'start': 1149.209, 'weight': 0.773, 'content': [{'end': 1162.618, 'text': "Well, I can just copy the hash here and I'm going to do a git revert and then paste in that hash and now it's going to come up here with a message and I'm just going to save that and exit out of that.", 'start': 1149.209, 'duration': 13.409}, {'end': 1174.701, 'text': 'and now, if I close out of there and do a git log, you can see that we now have three commits and these two bottom commits are completely untouched.', 'start': 1162.618, 'duration': 12.083}], 'summary': 'Performed git revert on a commit, resulting in three commits with two untouched', 'duration': 25.492, 'max_score': 1149.209, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk1149209.jpg'}], 'start': 937.662, 'title': 'Managing git commits and history', 'summary': "Covers managing git commits and history, including amending commits, resetting changes, detaching head state, creating branches, and using git reflog and revert to undo changes without rewriting history. it also explains how to use 'git revert' to undo previous commits, showing the process and its impact on commit history and file changes, highlighting the benefits of maintaining uncorrupted history and facilitating collaboration.", 'chapters': [{'end': 1141.061, 'start': 937.662, 'title': 'Managing git commits and history', 'summary': 'Covers managing git commits and history, including amending commits, resetting changes, detaching head state, creating branches, and using git reflog and revert to undo changes without rewriting history.', 'duration': 203.399, 'highlights': ['The chapter covers managing git commits and history, including amending commits, resetting changes, detaching head state, creating branches, and using git reflog and revert to undo changes without rewriting history.', 'Git reflog can be a lifesaver if critical files were thought to be lost or accidentally deleted, providing a way to recover lost changes.', 'Using git revert creates new commits to reverse the effects of earlier commits without modifying or deleting existing commits, preserving the commit history.', 'Demonstrating a walkthrough of managing git commits, including making initial commit, committing a complete function, amending commits, checking out and moving between branches, and using git reflog and revert to undo changes.', 'Highlighting the importance of git revert in situations where the need to undo commits arises after other people have already pulled those changes, without rewriting history.']}, {'end': 1283.079, 'start': 1141.521, 'title': 'Undoing commits with git revert', 'summary': "Explains how to use 'git revert' to undo previous commits, showing the process and its impact on commit history and file changes, and highlighting the benefits of maintaining uncorrupted history and facilitating collaboration.", 'duration': 141.558, 'highlights': ["The 'git revert' command allows for the undoing of previous commits, preserving commit history and ensuring that new commits only reflect the changes made to undo previous ones.", "Using 'git diff' after a 'git revert' allows for the comparison of the changes made in the original commit and its reverted version, illustrating the complete opposite actions taken in the revert.", "The process of using 'git revert' ensures that the commit history remains unchanged for collaborators, thereby preventing the corruption of history and facilitating seamless collaboration."]}], 'duration': 345.417, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/FdZecVxzJbk/pics/FdZecVxzJbk937662.jpg', 'highlights': ['The chapter covers managing git commits and history, including amending commits, resetting changes, detaching head state, creating branches, and using git reflog and revert to undo changes without rewriting history.', 'Using git revert creates new commits to reverse the effects of earlier commits without modifying or deleting existing commits, preserving the commit history.', 'Git reflog can be a lifesaver if critical files were thought to be lost or accidentally deleted, providing a way to recover lost changes.', 'Demonstrating a walkthrough of managing git commits, including making initial commit, committing a complete function, amending commits, checking out and moving between branches, and using git reflog and revert to undo changes.', 'Highlighting the importance of git revert in situations where the need to undo commits arises after other people have already pulled those changes, without rewriting history.']}], 'highlights': ['Using git revert creates new commits to reverse the effects of earlier commits without modifying or deleting existing commits, preserving the commit history.', 'The chapter covers managing git commits and history, including amending commits, resetting changes, detaching head state, creating branches, and using git reflog and revert to undo changes without rewriting history.', 'The .git directory indicates a Git repository, with a clean working directory.', 'The chapter covers common scenarios in Git where you may need to undo some mistakes or roll back bad commits.', 'The walkthrough assumes familiarity with basic command line functionality of Git.', 'Git reflog can be a lifesaver if critical files were thought to be lost or accidentally deleted, providing a way to recover lost changes.', 'Changing commit messages alters the unique hash and Git history, and should be avoided after pushing changes for others to see and pull from.', "The process of using 'git log --stat' is demonstrated to show the files changed within the commit, displaying the gitignore file as part of the last commit for the completed subtract function.", 'Git clean effectively cleans the working directory and removes untracked files and directories', "The potential risk of committing to the wrong branch is highlighted, emphasizing the common mistake due to switching back and forth, and the caution to only perform such changes if changes haven't been pushed yet."]}