1

I commited and upload the change to bitbucket like and commits are like:

change3
change2
change1

now i wanted to squash the 3 and 2 in to change 1 :git rebase -i HEAD~3 then squash the commits into change1.

its ok for local but when i want to push the squash commit it shows my remote is ahead of my current push. That's obvious i think as my remote has change3 and change2.

so My question is am i using squash in wrong way ? like in my situation when i want to squash already push commit into one how should i do it ?

I am very eager to know the right say of squash already push commit. TIA.

mubir
  • 719
  • 1
  • 8
  • 15
  • Using “stash” here is misleading/incorrect, as that refers to “git stash”, specifically. Updating to use “squash” or “rewrite history” here will lead to better question/reception and results. – user2864740 Jun 04 '20 at 03:28
  • Anyway, the drawback of force pushing a remote (or “rewriting remote history”) is that it may confuse and/or impede others - this is problematic on a mainline which others have already branched from (or merged back into). I would say: 1) don’t rewrite mainline history, and 2) have an agreement with team for rewriting history on work branches. I rewrite and force-push work branches frequently. However, I also try to minimize remote changes by keeping almost all rewriting local. – user2864740 Jun 04 '20 at 03:31
  • Yes, also usually, you need `-f` to force push your rebased changes because when you do `git rebase` you are essentially rewriting history and what has already been committed. So it's a preventive way to let you know that this will overwrite/modify your commits. – Rishi Raj Jun 04 '20 at 03:45
  • 1
    Here's a really nice answer for the same. I hope it helps! :) https://stackoverflow.com/questions/8939977/git-push-rejected-after-feature-branch-rebase#:~:text=If%20you%20rebase%20a%20branch,rebase%20will%20be%20quite%20unpleasant. – Rishi Raj Jun 04 '20 at 03:47
  • I squash and run "git push -f origin branch_name" but got following error: remote: Signed commits and tags are enforced for this repository. remote: d8d6019f2e8 was not signed. To ssh://git.XXX.com:AAAA/gen/xxx.git ! [remote rejected] branch_name -> branch_name (pre-receive hook declined) error: failed to push some refs to 'ssh://git.XXX.com:AAAA/gen/xxx.git' – mubir Jun 04 '20 at 11:34

0 Answers0