Is it possible in git to push commits one by one instead of all of them at once?

一世执手 提交于 2021-02-08 05:17:48

问题


I'm using a really unreliable connection and while I try to stage commits so none of them is over 20mb and/or to push them once they reach a size like that, sometimes it's not possible (a few of the assets can be big - I know it's not the best idea to use git for assets too) and there are 90% of chances my connection will fail before everything is sent.

Is it possible to push commits one by one, or can you suggest any other tips that could be useful for this case?


回答1:


Yes, it's not only possible but in fact pretty trivial. Instead of:

git push remote branch

just run:

git push remote <commit-hash>:branch

once for each commit to try pushing, in the appropriate (parent-most to child-most) order.

To automate this, assuming your remote is named origin and your branch is named branch and your origin/branch remote-tracking branch is up to date (run git fetch origin if not):

for rev in $(git rev-list --reverse origin/branch..branch); do
    git push origin $rev:branch;
done

which is really a one-liner split into three lines for StackOverflow posting purposes. (Note: this also assumes a more or less linear history; add --topo-order to guarantee things if not, but then you'll need --force and there are various bad ideas occurring here, so that's not the way to go: you'd want to split the pushes to use a temporary branch, or aggregate them at the merge points, perhaps.)



来源:https://stackoverflow.com/questions/45155541/is-it-possible-in-git-to-push-commits-one-by-one-instead-of-all-of-them-at-once

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!