Combine commits and push to forked repo

I have a repo (bitbucket.org/mine/project) which I forked from another repo (client.com/theirs/project). I made a bunch of commits to mine and now I want to push it back to their repo. I know I can push it to the upstream repo but it seems to include all the commits. My current workaround is I have both projects cloned and copying files from my repo working dir to their repo working dir and committing. Definitely not ideal. How do I squash my commits to a single commit when I push but leave my history intact ?

Attempt to illustrate the issue:

Client       ---- forked ------>      Bitbucket

their/project                         mine/project

commit #A                             commit #A
commit #B                             commit #B
commit #C                             commit #C

                                  |-  commit #1
                                  |   commit #2
                                  |   commit #3
commit #D    <----- how? ------   |-  commit #4   // I want to keep my commits

Referenced:

https://help.github.com/articles/merging-an-upstream-repository-into-your-fork/#platform-mac

Combining multiple commits before pushing in Git


I am not sure if there is any direct way to do that but I can suggest you a work around:

Take back up of your local branch. Let say if your branch is master and your back brach name is like master-backup. You can use below git command.

git branch master-backup

if you are on the same branch. or you can also use

git branch master-backup master

squash your commit follow the link. Now branch has single commit by combing all the commits.

git push origin master (Push your changes after squash to upstream with single commit)

git reset --hard master-backup (Get your old commits back to local master)


The owner of the their/project Github repo could always do this for you by choosing to Squash and Merge the commits from your branch via the Pull Request UI:

在这里输入图像描述

链接地址: http://www.djcxy.com/p/49052.html

上一篇: 我怎样才能在git中压缩

下一篇: 合并提交并推送到分叉的回购