Git by mistake committed the code in a branch where I am not supposed to resolution
Here is the scenario,
If I understand correctly, you want to create a new branch on top of an existing branch, and then move the mistakenly committed changes to this new branch before committing them. Here's how you can achieve that:
First, ensure you are on the branch where the mistaken commit was made. If you're not already on that branch, switch to it using
git checkout <existing_branch>.Create a new branch on top of the existing branch. You can do this by running:
cssgit checkout -b <new_branch_name>This will create a new branch starting from the current state of the existing branch.
Now that you're on the new branch, you need to identify the commit hash of the mistaken commit. You can use
git logto find it.Once you have the commit hash, you can reset the existing branch back to the commit before the mistaken commit. This will effectively remove the commit from the existing branch but keep it in your working directory. Run:
cssgit reset --hard HEAD^This command will move the HEAD pointer of the existing branch back one commit.
Now that the mistaken commit is removed from the existing branch, you can switch back to the new branch you created:
phpgit checkout <new_branch_name>Finally, you can cherry-pick the mistaken commit onto the new branch:
phpgit cherry-pick <commit_hash>Replace
<commit_hash>with the hash of the mistaken commit.Resolve any merge conflicts if they occur during the cherry-pick process.
Once the cherry-pick is successful, you can commit the changes to the new branch:
sqlgit commit -m "Moved mistaken commit to new branch"
Now, the mistaken commit is moved to the new branch, and the existing branch is back to its state before the mistake. You can continue working on the new branch as needed.
- Get link
- X
- Other Apps
Comments
Post a Comment