0

I'm trying to squash some commits that another user has pushed. Even though the commits have been squashed locally on my git log, when I try to do a force push to the master branch it doesn't change the commit history of the remote repo. Any ideas why?

Thanks.

msun
  • 41
  • 9
  • 1
    This is typically a bad idea. Are you sure you want to do it? Assuming you do, some output from the Git commands might be useful. It sounds like your force push didn't work. – Jamie Bisotti Jan 17 '17 at 16:38
  • Yeah, I'm sure I want to do it. It's a personal repo that was started by a friend and then handed over to me so nothing I do will actually affect anyone else. Git output says the force push does work and that "everything is up-to-date," but my commit history online says otherwise. – msun Jan 17 '17 at 16:44

1 Answers1

0

After a couple hours of searching, I found that I had mistakenly detached my HEAD (current directory that I'm in) from my master branch in the process of rebasing and making the commits, so I when I ran

git push --force origin master

git send me a confirmation message but didn't actually apply the changes that I'd made in the branch I was on, only the ones from my master branch. Whether or not one has a detached HEAD can be checked by running

git symbolic-ref HEAD

If it throws an error, then head is detached. Or

git branch

which shows what branch I'm on.

For other Git newbies, the solution was to merge my changes from the detached HEAD to the original branch by using

git branch temp (this creates a branch that is the same as the current repository)
git checkout temp (this attaches HEAD to temp)
git checkout master (moves HEAD back to master)
git merge temp (merges temp with master)
git push --force origin master (overwrites old commits that I've pushed)

More information can be found here: How can I reconcile detached HEAD with master/origin?

Thanks to all the people who answered stuff on this site.

Community
  • 1
  • 1
msun
  • 41
  • 9