0

Okay, I obviously have a little problem here understanding what I have to do in order to get this right.

I have pushed a lot of commits to the remote master which I'd like to squash now. In order to do so I've started a git rebase -i HEAD~20 session and used squash in order to squash some commits into one.

After some conflicts which I was able to resolve I was left with a "shortened" version of my local branch - but at this point I don't know how to get this onto the remote branch.

If I run git status it will tell me that the local and master branch differ in 1 and 11 commits.

If I'd run git pull at this point the whole rebase action gets undone and I am back to where I started.

So essentially I went from something like:

a                   b
o-->o-->o-->o-->o-->o
     \         /
      o-->o-->o

to

a   b
o-->o

but only locally. Can I squash the commits on the remote if I push local?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • @kaitoy whops, sorry. it's quite early for me - changed that :D – Stefan Falk Dec 20 '16 at 08:12
  • Typically, the normal git workflows do not allow you to rewrite history in the remote (what your'e doing here is rewrtiting history, removing those 11 commits from the master branch). If you are the only one working with that remote branch, you can do `git push -f` if you have the permissions for that. However, you should not do that if there are others users who are also working based on the same remote branch. – Alderath Dec 20 '16 at 08:15

2 Answers2

2

There is some confusion in the terms you use. There is such thing is 'push local'. The push action is from your local to the remote.

So, if you pushed your changes, they are shared in the remote repository.

Once those changes are shared, it is not recommended to squash them. Since anyone who already pulled your changes will have problems.

It is possible though. You need to force push your changes.

git push -f

Igal S.
  • 13,146
  • 5
  • 30
  • 48
1

Yes. Just do a force push by git push -f.

kaitoy
  • 1,545
  • 9
  • 16