Next, add some content to the newly created file, and then stage and commit the change:Īnd now, let’s say I push this to the remote repository.Īnd… Oh, oops, I actually had a typo there:I wrote tezt instead of text. Now our reachable git history looks like this: Let’s create another file 2.txt, stage and commit it: Then we can undo the last commit on this branch using git reset.Īwesome! So we’ve successfully achieved the desired state with the power of the well-known git reset command together with the new command we introduced, git cherry-pick.Ĭontinuing with another example… Pushing a faulty commit For that, we can simply switch to main branch again using git checkout main. What’s left for us to do is to change main to point to “Commit 1”. ![]() So now, our newly created commit points to “Commit 2” and feature_branch points to this new commit. At this point, let’s call it “Commit 3.1”. In other words, the new commit introduced the same changes as “Commit 3”, and it also has the same commit message – that is “Commit 3.” But this is a different commit object introduced with a different timestamp and thus it has a different SHA-1 value. This is exactly what we wanted: we applied the same changes that we had seen earlier, and this time, we applied them on feature_branch. You can now see the new commit, and the changes it introduced using git diff. Now the feature_branch points to the new commit. In this case, the changes to the file 1.txt generate a new commit including these specific changes, and then changes the pointer of the active branch. This basically takes the changes in “Commit 3” (with the SHA-1 value of c067afe7a50a54b1137aef0ed3b63f611b4ee8c7). If you want to apply these changes to the last commit on feature_branch, we need to be on feature_branch so we can use git checkout again. Note the changes this commit introduced using git diff. Start by adding the changes introduced in “Commit 3” to feature_branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |