git squash variants
If you just want to squash all commits into one.
1. The simplest way:
1 2 3 4 |
git checkout -b <temp-branch> origin/master git merge --squash origin/<branch-with-changes-you-need> git commit -m 'commit message' git push origin refs/heads/<temp-branch>:<new-branch> |
https://stackoverflow.com/a/5309051
If you have a message like ‘error: failed to push some refs to’, add --force to the last command
.
2. If you never merged other changes to <branch-with-changes-you-need> and it’s okay that you’ll be an author of all that changes, you can do the following:
1 2 3 4 5 |
git reflog # find commit BEFORE your first commit to <branch-with-changes-you-need> - for instance HEAD@{50} git reset --soft HEAD@{50} git commit -m 'commit message' git push origin refs/heads/<temp-branch>:<new-branch> |
https://stackoverflow.com/a/5201642
3. The most straightforward way is to
Use git rebase -i
https://stackoverflow.com/a/5189600
I never used it as I really don’t like rebase.
Well, you can do this like that:
1 2 3 |
git checkout -b <temp-branch> origin/master git rebase origin/<branch-with-changes-you-need> git push origin <branch-with-changes-you-need> --force |
Similar Posts
LEAVE A COMMENT
Для отправки комментария вам необходимо авторизоваться.