许多提交后在git中进行压缩

时间:2015-12-24 20:44:00

标签: git squash

我在github中很天真,我一直在尝试压缩我之前在远程执行的提交。但是有两个问题1)其他贡献者不断贡献,因此有许多提交高于我的提交2)我的提交是在git hub上没有按顺序看到。在快照中,我要合并的是四个提交enter image description here任何帮助都会很明显。

2 个答案:

答案 0 :(得分:1)

我建议始终 not 跟踪上游分支的本地git分支上工作。也就是说,在名为gh-pages的远程分支上开始新工作时,创建两个本地分支,如下所示:

# Create local gh-pages branch to track upstream
$ git co -b gh-pages origin/gh-pages
# Create personal branch for changes to be pushed to gh-pages
$ git co -b aayusharora-gh-pages

gh-pages的新提交被推送到上游时,将它们拉入您的本地gh-pages分支,然后在aayusharora-gh-pages分支之上 rebase 。也就是说,定期这样做:

# Check for new changes upstream
$ git co gh-pages
$ git pull
# Rebase your changes on top of any upstream changes
$ git co aayusharora-gh-pages
$ git rebase gh-pages

这将确保您的作品始终'任何上游变化。如果您最终准备推送更改,请执行以下操作:

$ git co gh-pages
$ git merge aayusharora-gh-pages
$ git push
# If finished, delete personal branch
$ git br -d aayusharora-gh-pages

以这种方式工作将确保您在处理任务时累积的任何更改将在您最终决定推送它们时显示为最近的提交。在此之前,您可以在aayusharora-gh-pages上重新设置/压缩任何提交,以使提交序列看起来任何您想要的方式。

答案 1 :(得分:0)

如果您同时拥有原点和上游

 git fetch upstream
 git reset upstream/gh-pages
 git commit

这会将您的本地分支重置为上游版本。保持暂存区域的变化。假设一切都没问题,这将只是你的差异