Git

How to Pull Specific Commit From Git Repository

Git is the most commonly used decentralized system which is utilized by large companies. The developers use it to track and collaborate on their project’s source code. It enables them to collaborate from every point of the globe and revert changes to codes if required. Users can also pull and push files and folders with repository log histories.

In this blog, we will discuss how to pull specific commits from the Git repository and merge the commits in the Git repository.

How to Pull Specific Commit From Git Repository?

The simple answer to the question, it’s not possible to pull a specific commit from a Git remote repository. But can fetch the latest data from the Git remote repository and then merge it with another branch. To do so, first, navigate to the Git repository and fetch all new data from Git remote repository using the “$ git fetch origin” command. Then, check the log history to view the commit with reference and switch to another branch. Lastly, run the “$ git merge <commit-ref>” command to merge the commits.

Now, let’s implement the stated concept!

Step 1: Launch Git Bash

Search and open up the Git terminal on your system with the help of the “Startup” menu:

Step 2: Navigate to Git Repository

Next, execute the “cd” command to move to the Git local repository:

$ cd "C:\Users\nazma\Git\demo5"

Step 3: Fetch Origin

Then, fetch the remote(origin) by executing the “git fetch” command:

$ git fetch origin

Here, you can see, the latest version of the remote repository is fetched successfully with all metadata:

Step 4: Check Repository Reference Log History

Check the Git local repository log history using the “git log” command with the “–oneline” option:

$ git log --oneline

Step 5: Switch Branch

Now, execute the “git checkout” with branch name you want to switch:

$ git checkout master

Step 6: Git Merge Commit

Lastly, merge the commit using its reference and bring all changes to the current repository:

$ git merge 440f087

That’s all. We have learned how to merge the commits in the Git repository.

Conclusion

On Git you are permitted to pull a specific commit from a Git remote repository. However, Git permits you to fetch the latest data from the Git remote repository and then merge it with another branch. To merge the commits of two branches, first, move to the Git repository and fetch all updated data from Git remote repository. Then, check log history to view commits and their reference and switch the branch. After that, merge the commits. This blog demonstrated the process of merging the commits in the Git repository.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.