0

Is there any option to remove these commits from my branch and back into normal? I have this status now:

Your branch is ahead of 'origin/release' by 4545 commits. (use "git push" to publish your local commits)

I don't want to push the changes into the origin. I am not sure what happened with my branch and got all of these commits.

OldProgrammer
  • 12,050
  • 4
  • 24
  • 45
Nibble
  • 17
  • 1
  • 2
    `git reset --hard` will reset the branch back to the last time you synced (pulled). I guess that means 4545 commits will be lost. Proceed with caution... A good general guide is here: https://sethrobertson.github.io/GitFixUm/fixup.html (one of many pages about using git - I'm pretty sure your question has been asked many times!) – topsail Jun 18 '22 at 15:59
  • Use a graphical repository browser like `gitk` to examine the state of your repository and see what happened with your branch. – mkrieger1 Jun 18 '22 at 16:03
  • I tried with git reset --hard but these commits are still there – Nibble Jun 18 '22 at 16:04
  • 2
    Don't just randomly try commands if you don't know what they do. – mkrieger1 Jun 18 '22 at 16:04
  • One possibility is that you did a pull from some other branch, while you had the release branch checked out, and that merged a bunch of changes from the other branch into your copy of the release branch. – Randy Leberknight Jun 18 '22 at 18:28
  • There is a command called git reflog which shows a history of things that happened in your local repo. Things like, checkout, pull, commit, merge. If you run git reflog that might help show how you got into this state. Then you can start figuring out how to get out. – Randy Leberknight Jun 18 '22 at 18:30
  • @RandyLeberknight you are right I check with git reflog and found that I pull from another branch by mistake. Thank you a lot – Nibble Jun 19 '22 at 10:08

1 Answers1

0

when you are currently on the branch itself

first back up your branch with another copy by creating a new branch from it git checkout -b release_backup

then you can just delete the branch git branch -D release

then git checkout origin/release

you will get a warning that you are on a detached head

now you can git checkout -b release to create a local copy from the branch