0

I'm working on a feature right now which I suppose to do it in a featureX branch BUT I forgot to create that branch and checkout into it. That cause a problem right now because that 2 commits already in my team remote master branch (we're using BitBucket) like so:

enter image description here

How do I move d40ef79 and 5e13fd7 into featureX branch so that I can continue working on that featureX branch and remove that 2 commits from master branch without losing recent commits created by my teammates (29ac4fb..1606c1a)?

I try first option inside this answer and it doesn't work for me. I also try git cherry-pick inside featureX branch (branch off from master) - also doesn't work for me.

Community
  • 1
  • 1
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98

1 Answers1

1

The most simple way is to do revert.

git revert <SHA-1>

Undo the git commit. Revert the changes made by the given commit.

reset and force push

# reset the branch to the desired commit
git reset <SHA-1>

There are other ways as well but they are less recommended (git push -f, git rebase, git filter-branch)


How to add the desired commit into different branch.

git cherry-pick <SHA-1>...<SHA-1>

Apply the change introduced by the commit at the tip of the master branch and create a new commit(s) with this change.

The syntax of the ... is a commit range. grab all commits from start (exclude) to the last one.

enter image description here


Read out the full git cherry-pick documentation for all the options you can use

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167