git - Remove wasted commit in our remote feature-branch -


i have tree

* commit origin/master | * commit origin/my-feature-branch | * commit  | * commit  | * commit  |/   | * commit origin/other-feature-branch |/ 

i want keep origin/master, want squash origin/my-feature-branch , make clean. "strategy" is:

git checkout my-feature-branch git rebase -i head~4 # ... leave first pick line , change others in squash # ... change commit messages 1 git push origin :my-feature-branch git push origin my-feature-branch 

my new tree clean.

* commit origin/master | * commit origin/my-feature-branch |/   | * commit origin/other-feature-branch |/ 

is correct way?

you've got right idea, though instead of deleting remote branch before pushing it, can force push directly with

git push origin my-feature-branch -f 

the reason why want delete remote branch first if force pushing disabled on remote, deleting first way sort of "cheat" , around restriction...though if restriction there, must not want force push, make sure rewriting branch ok team.

obligatory warning pushing rewritten commits public branches: if you're branch shared other developers, force pushing rewritten commits force other developers resynchronize work new commits, since they'll have copies of old ones. can difficult process, depending on git skills of team, make sure team ok doing this.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -