I have a repository with only one branch named main
.
Here is what git log --oneline --graph --all
outputs:
* 92033fe (HEAD -> main, origin/main) [test] Add some new tests
* 5e281c4 [style] Improve code formatting
* 50ccf6a release-1
| * 307cfba (tag: 1.0.0) release-1
|/
* 7d734b4 [feat] Add new feature
* 0b3c993 [fix] Fix some tests
What happened here is that I tried to tag, after the fact, commit 50ccf6a
as 1.0.0
, but did something wrong, and now I have this duplicated, and seemingly branching out, commit 307cfba
, which I want to get rid of, without affecting the rest of the branch.
Usually, I do git rebase -i --root main
, but this particular commit does not appear in the list of commits, only those I intend to keep:
pick 0b3c993 [fix] [fix] Fix some tests
pick 7d734b4 [feat] Add new feature
pick 50ccf6a release-1
pick 5e281c4 [style] Improve code formatting
pick 92033fe [test] Add some new tests
What is happening here?
CodePudding user response:
Commit 307cfba
is not on branch main
. If you want it off of branch main
, that's easy: do nothing at all, as it's already not there.
Commit 307cfba
is found because of tag 1.0.0
. If you want to not see 307cfba
at all, even with git log --all
, you'll need to delete tag 1.0.0
(or forcibly move it, but if you intend to do that, one easy way is to delete it first, then create it again).
CodePudding user response:
You can try to use --onto
option of rebase command (Try these steps on a copy of your repo to be safe).
Delete your tag first and recreate it on desired commit.
git tag -d 1.0.0
git tag -a 1.0.0 50ccf6a
git rebase --onto 7d734b4 50ccf6a~1