![]() ![]() Note the changes this commit introduced using git diff as follows: Start by adding the changes introduced in “Commit 3” to feature_branch. The commit which feature_branch is pointing to.The commit which “Commit 3” is pointing to.There are technically a few changes between the current “gitsaster” state and the desired state: Similar to that instance, we now want the change introduced in this commit on an already existing branch.Ī reminder, it’s useful to draw the current state versus the desired state: Oh, wait! What if you actually wanted this change to be introduced in the feature_branch, and not in main? We dealt with a similar case where we accidentally committed to the main branch, but actually wanted the commit to be recorded on a new branch. Now, switch back to the main branch using git checkout, make changes to the file 1.txt, and record these changes on main branch: Next, create a new file, and commit this addition to this feature branch: Source: Brief Committing to the wrong branchĪs I explained in the post about creating a repository from scratch, this creates the branch feature_branch, and also changes HEAD to point to that branch. This commit was added to the main branch, as we can verify using git log: ![]() I then added it to the index, and created a commit. To get started, let’s start by creating a small repository to play with:Īs you can see, I’ve created a repository and created a file called 1.txt, with the content hello. In this post, you’ll acquire additional tools to rewrite history and deal with “gitsasters.” Be sure to read Part 1 first, so you have the relevant background for overcoming git disasters. We then applied our knowledge to a few “gitsasters,” and saw that by understanding git and how it works, we can feel confident fixing cases when we need to rewrite history. In the previous post in this series, we learned about the command git reset, together with its three modes -soft, -mixed, and -hard. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |