

Step 1: Create a new branch from the infected master branch and named it something like that masterinfected Step 2: now hard reset the infected master branch for removing the polluted commits by. And after that, immediately commit those changes:Īn alternative is to do a -hard reset on branch A to HEAD~1, and to simply checkout out a new branch from commit b - the latest commit. I resolved this problem by the following approach.Now that you are here, simply create a new branch:.create a new branch from the current state of master git branch some-new-branch-name. Does not add newly created files) git commit -m'message describing changes' main is where it was before your changes. git commit -amend follow prompts to change the commit message. So the branch gets deleted but when I go back to brancha to continue work from where I left off, I see the changes I made in branchb are still there. Then, I deleted the branch thinking all the changes I made would get deleted too: git branch -d branchb. HEAD~1 means that you are resetting to a commit that is exactly one commit behind where you are right now. git add -u (means add any files which are in the git repo, but have changed. First I did a check-out of the original branch: git checkout brancha. In order to do this, we must use a git reset hard with a -– mixed flag. Once you are on Branch A, we want to forcibly rewrite the commit that the Branch A ref points to – we want to do a reset – but we still want to retain the files prior to them being staged – so we can transfer them to a new branch.Right now the ref for branch A is pointing to the commit B SHA. For each source branch commit that you cherry-pick, Git creates a corresponding commit on the target branch. Unlike merge or rebase, cherry-pick lets you select specific source branch commits.


(If I understand correctly): This is what you want: Git cherry-pick copies the changes from one or more source branch commits to a target branch.
