Reputation: 9255
I understand git pull
will update the working branch to the tip of a remote branch that it tracks. So let's say if I do git pull
, it will pull in all the latest changes. In my case, it will pull in 5 changes on top of my tree.
Is there a way to git pull
only the next change? i.e., if git pull
would put change 03, 04, 05, 06 and 07 on top of my tree, how do I pull only change 03? At the time of this command I do not know the commit ID of the next change it would pull in.
The tip of my tree is completely unaltered and will not have any merge conflicts and such.
Upvotes: 13
Views: 4862
Reputation: 40675
You can. Quite simple:
git fetch
git log --oneline --decorate --graph --all
git merge <some-commit-id>
#Repeat last line as often as you wish
#to incorporate upstream changes piecemeal.
The combination of flags to git log
is really useful to get a quick overview of what has happened, so much so that I always have a shell alias defined to use this precise combination:
alias gitlog='git log --oneline --decorate --graph'
With that alias, the above sequence becomes
git fetch
gitlog --all
git merge ...
...
Upvotes: 1
Reputation: 25377
This should be possible in theory. git status
shows there are 8 commits to pull, if a script could parse out the "8" and take an input (defaulting to 1) for the number of next commits you want. You could run git-pull-next 2
and it could do this:
newCommits
pullNextNCommits
, equal to cli input, defaults to 1newCommits
ago, minus pullNextNCommits
current_git_branch
as result of git rev-parse --abbrev-ref HEAD
git checkout <hash>
git checkout -b current_git_branch
TADA! Not impossible! Just have to write this script...
This answer is a community wiki, feel free to flesh out the psuedocode more
There's probably a better way to do this - since a git pull merge could have issues, it'd be better to take inspiration from the first answer here. But somehow, programmatically find the next commit hash.
Upvotes: 0
Reputation: 20656
Perhaps something like this?
git fetch
git merge <commit to merge>
To find the ID of the commit you want to merge, look it up in gitk after running the fetch.
Upvotes: 16