HOWTO · Git
How to Pull a Specific Commit From a Git Repository
Choose the right Git operation to apply, inspect, merge, or reset to a specific commit, with clear commands and safety guidance.
On this page
To bring one commit’s changes onto your current branch, fetch the remote history and use git cherry-pick <commit-id>. Create a branch at that commit when you want to inspect or continue from its historical state. Use git merge or git pull when you intend to integrate branch history, which can include earlier commits too. Use git reset only when you mean to move your current branch to an earlier point.
Choose the right operation for a specific commit
These operations have different outcomes. git cherry-pick applies the change introduced by a selected commit as a new commit on your current branch. Creating a branch at a commit starts work from that snapshot. Merging a commit brings in its reachable history that is not already present. Pull fetches from a remote and integrates according to the configured pull behavior. Reset moves the current branch reference; --hard also replaces the working tree and index. Choose based on whether you need one change, a historical starting point, remote history, or a branch rollback.
Find a commit hash
Run git log to see commit IDs, authors, and messages. For a compact list, use git log --oneline. Copy the ID shown for the desired commit; Git accepts an unambiguous abbreviated ID as well as a full object ID. If the commit exists only on a remote, fetch first with git fetch origin, then inspect the updated history. Replace origin with your remote name and <commit-id> with the chosen ID.
Apply one commit with git cherry-pick
Fetch the remote branch or its objects, then apply the selected commit with git fetch origin followed by git cherry-pick <commit-id>. This is the direct choice when you want one commit’s change without merging a whole branch. The following local example creates a commit on a topic branch and applies it to main:
repo=$(mktemp -d)
trap 'rm -rf "$repo"' EXIT
git -C "$repo" init -q -b main
git -C "$repo" config user.name "Example User"
git -C "$repo" config user.email "example@example.com"
printf 'base\n' > "$repo/notes.txt"
git -C "$repo" add notes.txt
git -C "$repo" commit -qm "Add notes"
git -C "$repo" switch -q -c topic
printf 'one change\n' >> "$repo/notes.txt"
git -C "$repo" add notes.txt
git -C "$repo" commit -qm "Add one change"
commit_id=$(git -C "$repo" rev-parse HEAD)
git -C "$repo" switch -q main
git -C "$repo" cherry-pick "$commit_id"
printf 'Applied one commit to main.\n'
[main 5ede2b1] Add one change
Date: Mon Oct 26 03:50:14 2026 +0000
1 file changed, 1 insertion(+)
Applied one commit to main.
If changes conflict, resolve the marked files, stage the resolutions with git add, and continue with git cherry-pick --continue. To stop and return to the pre-operation state, use git cherry-pick --abort. Finish or abort before starting another operation.
Create a branch at a specific commit
To inspect or build from a commit without moving your current branch, fetch the remote and run git checkout -b review-branch <commit-id>. This creates and switches to review-branch at that commit. The branch contains that commit’s history; later commits on another branch are not included unless you merge or cherry-pick them.
Fetch and merge a commit from a remote
Run git fetch origin to update remote-tracking references without integrating them. Then use git merge <commit-id> to merge the selected commit and its reachable history that is missing from your current branch. This may bring in ancestors, so it is not equivalent to applying only the selected change. Use git log --oneline --graph --decorate to review the resulting history.
Use git pull with a commit hash
A remote may allow fetching a raw commit ID if that object is reachable and the server permits the request. Support varies, so git pull origin <commit-id> is not a portable way to select one change. When accepted, pull fetches and integrates according to your configuration; it does not mean “apply only this commit.” For a single change, fetch and cherry-pick. Otherwise, fetch a named branch and pull or merge that branch.
Reset a branch to a specific commit
Use git reset --hard <commit-id> only when you intend to move the current branch and replace the index and working tree with that commit. It can discard uncommitted changes. If you later push the moved branch, collaborators may need to reconcile rewritten shared history. Check git status and preserve any work you need before resetting. For a safer undo that keeps published history, use git revert <commit-id> to create a new commit that reverses the selected change.
FAQ
How do I find a commit ID? Use git log or git log --oneline; fetch first if the commit is only available from a remote.
What if cherry-pick reports conflicts? Resolve and stage each file, then run git cherry-pick --continue; use git cherry-pick --abort to cancel.
Can I cherry-pick several commits? Yes. Give git cherry-pick multiple IDs in the intended order, or use a commit range after checking which endpoints it includes.
Is reset the same as revert? No. git reset moves the branch reference and may replace local files; git revert records a new commit that undoes an earlier change.