多次提交后压缩 git
Squashing in git after many commits
我在 github 中很天真,我一直在尝试压缩我之前在远程所做的提交。但是有两个问题 1)其他贡献者不断贡献,因此上面有很多提交我的提交 2) 我的提交在 git hub.In 快照上没有按顺序显示,这是我必须合并的四个提交 enter image description here任何帮助都会很明显。
我建议始终在本地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
分支,然后 rebase 它们在您的 aayusharora-gh-pages
支线。也就是说,定期执行此操作:
# 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
这将确保您的工作始终 'on top of'任何上游更改。当您最终准备好推送更改时,请执行:
$ git co gh-pages
$ git merge aayusharora-gh-pages
$ git push
# If finished, delete personal branch
$ git br -d aayusharora-gh-pages
以这种方式工作将确保您在处理任务时积累的任何更改在您最终决定推送它们时看起来是最新的提交。在那之前,您可以 rebase/squash 在 aayusharora-gh-pages
上进行任何提交,以使提交序列看起来像您想要的任何方式。
如果你同时拥有来源和上游
git fetch upstream
git reset upstream/gh-pages
git commit
这会将您的本地分支重置为上游版本。将更改保留在暂存区域中。假设一切正常提交,这将只是你的不同
我在 github 中很天真,我一直在尝试压缩我之前在远程所做的提交。但是有两个问题 1)其他贡献者不断贡献,因此上面有很多提交我的提交 2) 我的提交在 git hub.In 快照上没有按顺序显示,这是我必须合并的四个提交 enter image description here任何帮助都会很明显。
我建议始终在本地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
分支,然后 rebase 它们在您的 aayusharora-gh-pages
支线。也就是说,定期执行此操作:
# 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
这将确保您的工作始终 'on top of'任何上游更改。当您最终准备好推送更改时,请执行:
$ git co gh-pages
$ git merge aayusharora-gh-pages
$ git push
# If finished, delete personal branch
$ git br -d aayusharora-gh-pages
以这种方式工作将确保您在处理任务时积累的任何更改在您最终决定推送它们时看起来是最新的提交。在那之前,您可以 rebase/squash 在 aayusharora-gh-pages
上进行任何提交,以使提交序列看起来像您想要的任何方式。
如果你同时拥有来源和上游
git fetch upstream
git reset upstream/gh-pages
git commit
这会将您的本地分支重置为上游版本。将更改保留在暂存区域中。假设一切正常提交,这将只是你的不同