Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to 'git pull' only the next commit?

Tags:

git

git-pull

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.

like image 740
Adam S Avatar asked Apr 10 '12 22:04

Adam S


People also ask

How do I pull only a specific commit?

Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want. "Cherry pick" the commits you want into this branch. Run this command: git cherry-pick super-long-hash-here . That will pull just this commit into your current branch.

Can I do git pull before commit?

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched. Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

Should I commit first or pull first?

Always Pull Before a Push Doing so will ensure that your local copy is in sync with the remote repository. Remember, other people have been pushing to the remote copy, and if you push before syncing up, you could end up with multiple heads or merge conflicts when you push.

How do I pull another commit?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.


1 Answers

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.

like image 55
Stuart Golodetz Avatar answered Oct 11 '22 23:10

Stuart Golodetz