Git pull till a particular commit

I want to do a git pull but only till a specific commit.

 A->B->C->D->E->F (Remote master HEAD)

so suppose my local master HEAD points to B, and I want to pull till E. What should I do ?

This is not pulling a specific commit, this is pulling upto a specific commit.

  • How can I make a folder in one git repository dependent on another?
  • How to manage a project on GitHub that has an external git dependency not stored on GitHub
  • Getting repository information using pygithub3 for Python
  • How to setup jenkins for all the private repositories under an organization in GitHub?
  • Difference between Git and GitHub
  • Cannot commit from command line using github 2FA
  • Setting upstream branch to remote with different name than your local
  • Move .git repo to parent directory
  • 3 Solutions collect form web for “Git pull till a particular commit”

    git pull is nothing but git fetch followed by git merge. So what you can do is

    git fetch remote example_branch

    git merge <commit_hash>

    First, fetch the latest commits from the remote repo. This will not affect your local branch.

    git fetch origin
    

    Then checkout the remote tracking branch and do a git log to see the commits

    git checkout origin/master
    git log
    

    Grab the commit hash of the commit you want to merge up to (or just the first ~5 chars of it) and merge that commit into master

    git checkout master
    git merge <commit hash>
    

    If you merge a commit into your branch, you should get all the history between.

    Observe:

    $ git init ./
    Initialized empty Git repository in /Users/dfarrell/git/demo/.git/
    $ echo 'a' > letter
    $ git add letter
    $ git commit -m 'Initial Letter'
    [master (root-commit) 6e59e76] Initial Letter
     1 file changed, 1 insertion(+)
     create mode 100644 letter
    $ echo 'b' >> letter
    $ git add letter && git commit -m 'Adding letter'
    [master 7126e6d] Adding letter
     1 file changed, 1 insertion(+)
    $ echo 'c' >> letter; git add letter && git commit -m 'Adding letter'
    [master f2458be] Adding letter
     1 file changed, 1 insertion(+)
    $ echo 'd' >> letter; git add letter && git commit -m 'Adding letter'
    [master 7f77979] Adding letter
     1 file changed, 1 insertion(+)
    $ echo 'e' >> letter; git add letter && git commit -m 'Adding letter'
    [master 790eade] Adding letter
     1 file changed, 1 insertion(+)
    $ git log
    commit 790eade367b0d8ab8146596cd717c25fd895302a
    Author: Dan Farrell 
    Date:   Thu Jul 16 14:21:26 2015 -0500
    
        Adding letter
    
    commit 7f77979efd17f277b4be695c559c1383d2fc2f27
    Author: Dan Farrell 
    Date:   Thu Jul 16 14:21:24 2015 -0500
    
        Adding letter
    
    commit f2458bea7780bf09fe643095dbae95cf97357ccc
    Author: Dan Farrell 
    Date:   Thu Jul 16 14:21:19 2015 -0500
    
        Adding letter
    
    commit 7126e6dcb9c28ac60cb86ae40fb358350d0c5fad
    Author: Dan Farrell 
    Date:   Thu Jul 16 14:20:52 2015 -0500
    
        Adding letter
    
    commit 6e59e7650314112fb80097d7d3803c964b3656f0
    Author: Dan Farrell 
    Date:   Thu Jul 16 14:20:33 2015 -0500
    
        Initial Letter
    $ git checkout 6e59e7650314112fb80097d7d3803c964b3656f
    $ git checkout 7126e6dcb9c28ac60cb86ae40fb358350d0c5fad
    Note: checking out '7126e6dcb9c28ac60cb86ae40fb358350d0c5fad'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b new_branch_name
    
    HEAD is now at 7126e6d... Adding letter
    $ git checkout -b B 7126e6dcb9c28ac60cb86ae40fb358350d0c5fad
    Switched to a new branch 'B'
    $ git pull 790eade367b0d8ab8146596cd717c25fd895302a
    fatal: '790eade367b0d8ab8146596cd717c25fd895302a' does not appear to be a git repository
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    $ git merge 7f77979efd17f277b4be695c559c1383d2fc2f27
    Updating 7126e6d..7f77979
    Fast-forward
     letter | 2 ++
     1 file changed, 2 insertions(+)
    $ cat letter
    a
    b
    c
    d
    
    Git Baby is a git and github fan, let's start git clone.