Quitch
Quitch

Reputation: 89

Why did rebase and hard reset give me different results?

I have forked another repo to create pull requests for it. No one else is contributing to that repo during the period described here.

My first commits I submit as a pull request to the remote repo. This is accepted. My second pull request has errors that need fixing, but this requires reverting the files to a previous state as the issue is I broke formatting as my editor change them to a different format.

This would appear to be something I can use rebase for. However, when I use "git rebase upstream/master" while having my master branch checked out I am told "Current branch master is up to date." My branch is currently one commit ahead of upstream, and my understanding of rebase is that it should move HEAD on my branch to the last commit on the branch I'm rebasing against.

While reading the documentation to see what I'd done wrong I noticed that "git reset --hard " was supposed to do the same thing. So I did "git reset --hard upstream/master" and this has the desired effect of moving HEAD to the accepted pull request of mine.

My question is that given both are supposed to do the same thing why did I get different results?

Upvotes: 1

Views: 407

Answers (1)

VonC
VonC

Reputation: 1324278

However, when I use "git rebase upstream/master" while having my master branch checked out I am told "Current branch master is up to date."

That would replay master on top of upstream/master, which means there is nothing to do, since upstream/master commits are already part of master.

Typically, when you submit a PR, you want to be sure those are done on top of the most up-to-date upstream master branch, meaning the updated original repo (which was forked)

git checkout my_PR_branch
git fetch upstream
git rebase upstream/master

This assume your PR is done in a branch instead of master.
If your PR was done on master, then:

  • create a branch from your current master: git branch mypr; git push -u origin mypr; # make a new PR from that branch.
  • reset your master to origin/master: git fetch and git reset --hard origin/master.

Upvotes: 1

Related Questions