0

I was working on a feature branch to which I had pushed some commits. I had an issue with my machine and had to do a fresh install and pull the remote branch to continue working on the issue. the problem comes in when I try to squash all the commits. If try

git rebase -i master

I only get commits after the fresh install. If I then try using the SHA of the commit before my first commit on that branch,I have other commits that belong to other branches that i do not want to modify. Same applies if i try specifying the number of commits as in

git rebase -i HEAD~10

(I have 10 commits in the branch)

I have tried everything I have come across in similar posts including

soft --reset

but nothing seems to work in this case How can I solve this

Marek R
  • 32,568
  • 6
  • 55
  • 140
mutisya
  • 1
  • 2
  • `get commits after the fresh install` What? I have no idea what is your problem. Also I'm not sure you are aware what are you doing. Are you fluent with interactive rebase? – Marek R Jul 19 '21 at 15:17
  • Maybe you should use `git log --graph --pretty=format:"%s"` to show us current state of your repository and desired outcome. – Marek R Jul 19 '21 at 15:23

1 Answers1

0

It sounds like you've already merged your local branch into the master branch:

  • When you rebase onto the master branch, some commits from your feature branch are not listed in the editor. That suggests that those commits have already been merged into the master branch.

  • When you rebase onto a specific SHA from the feature branch and you see a lot of commits from other branches, that says they're already included in your current branch.

I suggest using a graphical Git client like Fork, or using git log --oneline --graph, to view the commit history and see if some branches have merged that you weren't expecting.

If you can show the commit history, someone might be able to show how to recover. Without knowing for sure what happened, we might guess wrong what commands you should run, and accidentally cause more problems.

Stephen Jennings
  • 12,494
  • 5
  • 47
  • 66
  • You were right, I had done a ``` git pull `` which is ```git fetch``` && ```git merge```. I was able to resolve this by deleting the local branch, checkout to master branch, ``` git fetch``` and finally ```git checkout --track /``` to create a local branch with the same name as the remote branch. I could the commit all changes on the branch – mutisya Jul 20 '21 at 09:09