In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about the difference between "git fetch" and "git pull" in git. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Both git fetch and git pull can update remote repositories locally, so what's the difference between them? There are several concepts that have to be raised if you want to figure out this problem.
FETCH_HEAD: is a version link, recorded in a local file, pointing to the end version of the branch that has been removed from the remote repository.
Commit-id: after each local work is completed, a git commit operation is performed to save the current work to the local repo, and a commit-id is generated, which is a serial number that uniquely identifies a version. After using git push, the serial number is also synchronized to the remote repository.
With the above concepts, let's talk about git fetch.
Git fetch: this will update the latest commit-id of all branches contained in remote repositories in git remote and record it in the .git / FETCH_HEAD file
Git fetch updates the remote repository in the following ways:
Git fetch origin master:tmp / / create a new temp branch locally, and download the master branch code of the remote origin repository to the local temp branch git diff tmp// to compare the difference between the local code and the code just downloaded remotely. Git merge tmp// merges the temp branch to the local master branch git branch-d temp//. If you do not want to keep the temp branch, you can use this step to delete.
(1) if you use git fetch directly, the steps are as follows:
Create and update local remote branches. That is, create and update the origin/xxx branch and pull the code to the origin/xxx branch.
Set the current branch-origin/ current branch correspondence in FETCH_HEAD, for example, git merge can merge the origin/abc into the abc branch.
(2) git fetch origin
Only the remote to be fetch is manually specified. Usually defaults to master when no branch is specified
(3) git fetch origin dev
Specify the remote remote and FETCH_HEAD, and pull only the commit for that branch.
This command accesses the remote warehouse and pulls all the data you don't have yet. After the execution is complete, you will have references to all branches in that remote repository, which can be merged or viewed at any time.
If you clone a repository using the git clone command, the command automatically adds it as a remote repository (git remote-v) with the abbreviation "origin" by default. So, git fetch origin grabs all the work that has been pushed since the clone (or the last crawl). It is important to note that the git fetch command pulls data to your local repository-it does not automatically merge or modify your current work. You must manually incorporate it into your work when you are ready.
If you have a branch set to track a remote branch, you can use the git pull command to automatically grab and merge the remote branch into the current branch. This may be a simpler or more comfortable workflow for you; by default, the git clone command automatically sets the local master branch to track the master branch of the cloned remote repository (or the default branch of whatever name). Running git pull usually grabs data from the server that was originally cloned and automatically attempts to merge to the current branch.
Git pull: first, based on the local FETCH_HEAD record, compare the local FETCH_HEAD record with the version number of the remote repository, then git fetch gets the data of the subsequent version of the remote branch currently pointed to, and then uses git merge to merge it with the local current branch. So we can think of git pull as a combination of git fetch and git merge.
The usage of git pull is as follows:
Git pull: / / retrieve the update of a branch of the remote host and merge it with the specified branch locally.
Therefore, compared to git pull, git fetch is equivalent to getting the latest version locally remotely, but does not automatically merge. If you need to have a choice to merge git fetch is a better choice. Git pull will be faster when the effect is the same.
Note: updating the code with git pull is relatively simple and violent, but according to commit ID, their actual implementation principles are not the same, so instead of using git pull, it is safer to use git fetch and git merge.
Thank you for reading! This is the end of the article on "what's the difference between" git fetch "and" git pull "in git. I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.