Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull only certain number of commits

I have a local git repo and I need to update it. Howhever, the online repo is way ahead of my local copy. I am behind a extremely slow connection. When I use git pull -v --progress, I start to see the progress but after a while, I get this error:

efrror: RPC failed: result = 18, HTTP code = 200 | 5.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

This is due to my very slow connection. I need to know if there is a way to get, say only the first commit ahead of my local repo, to see if I can update my local repo one step at a time.

Important: What I would like to know is if there is a way to pull a # of commits ahead of my local copy, not a specific commit.

like image 536
Alfredo A. Avatar asked Nov 09 '22 18:11

Alfredo A.


1 Answers

If you want to pull $N commits of the branch $BRANCH you could do this (assuming that you currently are in $BRANCH):

git log $BRANCH..origin/$BRANCH --pretty=format:%H | tail -$N | head -1 | git pull origin 

Now, step by step:

git log $BRANCH..origin/$BRANCH

Will give a list of the commits that differ between your local branch and the remote one, and the --pretty=format:%H option would just show the commit id, avoiding other information as the author, date or commit message.

tail -$N | head -1

Given a list, tail -N will give you the last N lines of it, and head -1 will give you the first one. So if we put them both together, we obtain the last Nth line of a list.

| git pull origin 

Will just pull the commit id passed through the pipe into your current branch.

like image 82
Juan Avatar answered Nov 27 '22 04:11

Juan