1

Of the few times I have squashed Git commits, it took some manual work to pick the previous commits I wanted to squash.

Is there some way to so this automatically - my goal is to squash all previous commits that have not already been pushed to a particular remote branch.

To elaborate, say I have 1 local branch called "dev" and 2 remotes, public and private. I commit and push all I want to the private remote, to a branch called "dev", let's call that private/dev. But on the public remote I want to keep things clean and tidy, and to keep one standard branch called "master", let's call that public/master. So like I said, for all the commits that have not already made it to the public remote master branch, I want to squash those into one big commit, and the push to public/master

How can I achieve that? Seems complicated.

4

1 回答 1

3

public/master您只需通过(public作为您的公共远程的名称,并且master- 例如 - 作为目标分支)创建一个临时分支

而你使用merge --squash(参见“在 git 中,之间有什么区别?merge --squashrebase ”)

 git checkout -b temp public/master
 git merge  --squash dev
 # since merge --squash does not produce a commit:
 git commit -m "squash dev"
 git push public temp:master
 git checkout dev
 git branch -d temp

关于冒号语法,请参阅“ git push branch to a new repo with a different name git push和.
它允许将本地分支推送到具有不同名称的远程分支。

于 2016-10-22T04:55:28.747 回答