質問

I understand git rebase a bit. And I understand git reflog and git reset --hard a bit, too. But the SO answers and blog posts I've tried can't seem to help me fix this error I've made.

I am working on a change to Marionette. I was doing as I normally do, squashing my commits into one, when I noticed at some point that I had actually somehow 'attached' a bunch of commits to my PR. It now lists 6 commits, with my latest one being separate from the others.

I'm unsure if this is what squashing looks like when you squash commits from multiple users, so my first question is: what is going on here? Were they accidentally squashed?

The second question is how might I fix this? Nothing I do seems to work. I git reset --hard to before I did any rebases, and it still shows those 6 commits as unpushed commits. Even if I reset --hard all the way to when I cloned the repo, it still lists those other commits.

What is going on here? Do you have any ideas on how I can fix this?

役に立ちましたか?

解決

And here's the answer (credits go to cobbweb):

  1. Hard reset your repository entirely
    git reset --hard origin/master

    What this does is update your repository to be in the same state as the remote repository. It will also set all of the commits (both the ones you want & the ones you don't want) as unpushed commits in the local branch. This is where you want to be.

  2. Select only the commit that you want
    git cherry-pick {{ SHA }}

    where {{SHA}} is the commit ID for that thing. It will look something like 344dc098ffle90aaef3.

  3. Force the push and you should be good to go.
    git push --force

If you'd like to know more on what's going on here run a google/SO search on each of the things we've done here: hard resets, cherry-picking, and force pushing. You'll find a wealth of information about them.

Note: This problem and solution involved working on just the master branch. Things might be a bit different if you are dealing with a situation with more than one branch.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top