0

I have a repository containing branch1.

It has two commits 123weew (current) and gwehhj12(previous).
I want to move branch1 to the previous commit and create a new branch2 at existing 123weew commit id.

How can this be done?

At worse, I just want to delete commit 123weew so that I can start fresh.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
itthrill
  • 1,241
  • 2
  • 17
  • 36
  • No the question is different. I want to move my branch to previous commit – itthrill May 11 '18 at 21:07
  • This effectively accomplishes what you want to do. You can take your previous commit id of `gwehhj12` for branch `branch1` and simply do `git branch branch2 gwehhj12`. This will make the branch `branch2` from `branch1` at commit `gwehhj12`. If you want to completely discard your commit on `branch1`, which isn't recommended, you can look at the question here: https://stackoverflow.com/questions/3293531/how-to-permanently-remove-few-commits-from-remote-branch I highly discourage this, however, due to possible issues you could run into when working with teams. – B. Fleming May 11 '18 at 21:17

1 Answers1

1

I would do this in two steps. First, create the new branch at the current commit you're at:

git branch branch2 - this creates the new branch.

git reset --hard HEAD~1 - this resets the branch you're on (still branch1) to the commit before, resetting all files to the state of your previous commit.

Narigo
  • 2,979
  • 3
  • 20
  • 31