Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

commit

push

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?

like image 874
ManuelAMS Avatar asked Dec 24 '22 16:12

ManuelAMS


2 Answers

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.)

like image 132
torek Avatar answered Dec 26 '22 10:12

torek


Just to clarify the other answer:

git push <remote name> <commit SHA>:<remote branch name>

Example:

git push origin c01c4fa28a0c864c2d09f8fb43a80c46dce9c7c6:master
like image 38
GG. Avatar answered Dec 26 '22 09:12

GG.