git pull git_Git Pull解释

git pull git

git pull is a Git command used to update the local version of a repository from a remote.

git pull是一个Git命令,用于从远程更新存储库的本地版本。

It is one of the four commands that prompts network interaction by Git. By default, git pull does two things.

它是提示Git与网络交互的四个命令之一。 默认情况下, git pull做两件事。

  1. Updates the current local working branch (currently checked out branch)

    更新当前的本地工作分支(当前已签出的分支)
  2. Updates the remote tracking branches for all other branches.

    更新所有其他分支的远程跟踪分支。

git pull fetches (git fetch) the new commits and merges (git merge) these into your local branch.

git pull提取( git fetch )新的提交并将它们合并( git merge )到您的本地分支中。

This command’s syntax is as follows:

该命令的语法如下:

# General format
git pull OPTIONS REPOSITORY REFSPEC

# Pull from specific branch
git pull REMOTE-NAME BRANCH-NAME

in which:

其中:

  • OPTIONS are the command options, such as --quiet or --verbose. You can read more about the different options in the Git documentation

    OPTIONS是命令选项,例如--quiet--verbose 。 您可以在Git文档中了解有关不同选项的更多信息

  • REPOSITORY is the URL to your repo. Example: https://github.com/freeCodeCamp/freeCodeCamp.git

    仓库是您的仓库的URL。 示例: https//github.com/freeCodeCamp/freeCodeCamp.git

  • REFSPEC specifies which refs to fetch and which local refs to update

    REFSPEC指定要获取的参考和要更新的本地参考

  • REMOTE-NAME is the name of your remote repository. For example: origin.

    REMOTE-NAME是您的远程存储库的名称。 例如: origin

  • BRANCH-NAME is the name of your branch. For example: develop.

    BRANCH-NAME是您的分支的名称。 例如: 开发

Note

注意

If you have uncommitted changes, the merge part of the git pull command will fail and your local branch will be untouched.

如果您尚未提交更改,则git pull命令的合并部分将失败,并且本地分支将保持不变。

Thus, you should always commit your changes in a branch before pulling new commits from a remote repository.

因此, 从远程存储库中提取新提交之前 ,应始终在分支中提交更改

Table of Contents

目录

使用git pull (Using git pull)

Use git pull to update a local repository from the corresponding remote repository. Ex: While working locally on master, execute git pull to update the local copy of master and update the other remote tracking branches. (More information on remote tracking branches in the next section.)

使用git pull从相应的远程存储库更新本地存储库。 例如:在master本地工作时,执行git pull来更新master的本地副本并更新其他远程跟踪分支。 (在下一部分中,有关远程跟踪分支的更多信息。)

But, there are a few things to keep in mind for that example to be true:

但是,要使该示例正确,需要牢记以下几点:

The local repository has a linked remote repository

本地存储库具有链接的远程存储库

  • Check this by executing git remote -v

    通过执行git remote -v检查

  • If there are multiple remotes, git pull might not be enough information. You might need to enter git pull origin or git pull upstream.

    如果有多个遥控器,则git pull可能没有足够的信息。 您可能需要输入git pull origingit pull upstream

The branch you are currently checked out to has a corresponding remote tracking branch

当前已签出的分支具有相应的远程跟踪分支

  • Check this by executing git status. If there is no remote tracking branch, Git doesn’t know where to pull information from.

    通过执行git status检查。 如果没有远程跟踪分支,则Git不知道何处提取信息。

分布式版本控制 (Distributed Version Control)

Git is a Distributed Version Control System (DVCS). With DVCS, developers can be working on the same file at the same time in separate environments. After pushing code up to the shared remote repository, other developers can pull changed code.

Git是一个分布式版本控制系统 (DVCS)。 使用DVCS,开发人员可以在不同的环境中同时处理同一文件。 代码送到共享的远程存储库后,其他开发人员可以提取更改的代码。

Git中的网络交互 (Network interactions in Git)

There are only four commands that prompt network interactions in Git. A local repository has no awareness of changes made on the remote repository until there is a request for information. And, a remote repository has no awareness of local changes until commits are pushed.

在Git中只有四个命令可以提示网络交互。 在请求信息之前,本地存储库不知道对远程存储库所做的更改。 而且,在推送提交之前,远程存储库不了解本地更改。

The four network commands are:

四个网络命令是:

  • git clone

    git clone

  • git fetch

    git fetch

  • git pull

    git pull

  • git push

    git push

DVCS中的分支 (Branches in DVCS)

When working with Git, it can feel like there are lots of copies of the same code floating all over the place. There are different versions of the same file on each branch. And, different copies of the same branches on every developer’s computer and on the remote. To keep track of this, Git uses something called remote tracking branches.

使用Git时,感觉到处都有很多相同代码的副本。 每个分支上的同一文件有不同版本。 并且,同一分支的不同副本在每个开发人员的计算机和远程计算机上。 为了对此进行跟踪,Git使用了一种称为远程跟踪分支的东西。

If you execute git branch --all within a Git repository, remote tracking branches appear in red. These are read-only copies of the code as it appears on the remote. ( When was the last network interaction that would have brought information locally? Remember when this information was last updated. The information in the remote tracking branches reflects the information from that interaction.)

如果您在Git存储库中执行git branch --all ,则远程跟踪分支将以红色显示。 这些是遥控器上显示的代码的只读副本。 (最后一次在本地进行网络交互的信息是什么时候?请记住该信息的最新更新时间。远程跟踪分支中的信息反映了来自该交互的信息。)

With remote tracking branches, you can work in Git on several branches without network interaction. Every time you execute git pull or git fetch commands, you update remote tracking branches.

使用远程跟踪分支 ,您可以在多个分支上的Git中工作,而无需网络交互。 每次执行git pullgit fetch命令时,都会更新远程跟踪分支

git fetch加上git merge (git fetch plus git merge)

git pull is a combination command, equal to git fetch + git merge.

git pull是一个组合命令,等于git fetch + git merge

git获取 (git fetch)

On its own, git fetch updates all the remote tracking branches in local repository. No changes are actually reflected on any of the local working branches.

git fetch自行更新本地存储库中的所有远程跟踪分支。 实际上,任何本地工作分支均未反映任何更改。

git合并 (git merge)

Without any arguments, git merge will merge the corresponding remote tracking branch to the local working branch.

没有任何参数, git merge将把相应的远程跟踪分支合并到本地工作分支。

git pull (git pull)

git fetch updates remote tracking branches. git merge updates the current branch with the corresponding remote tracking branch. Using git pull, you get both parts of these updates. But, this means that if you are checked out to feature branch and you execute git pull, when you checkout to master, any new updates will not be included. Whenever you checkout to another branch that may have new changes, it’s always a good idea to execute git pull.

git fetch更新远程跟踪分支。 git merge使用相应的远程跟踪分支更新当前分支。 使用git pull ,您将获得这些更新的两个部分。 但是,这意味着如果您签出到feature分支并执行git pull ,当您签出到master ,将不包括任何新更新。 每当您结帐到可能有新更改的另一个分支时,执行git pull总是一个好主意。

git pull in IDE (git pull in IDEs)

Common language in other IDES may not include the word pull. If you look out for the words git pull but don’t see them, look for the word sync instead.

其他IDES中的通用语言可能不包含pull 。 如果您寻找git pull一词但看不到它们,请寻找sync一词。

将远程PR(Pull Request)提取到本地仓库中 (fetching a remote PR (Pull Request) in to local repo)

For purposes of reviewing and such, PRs in remote should be fetched to the local repo. You can use git fetch command as follows to achieve this.

为了进行审核,应该将远程的PR提取到本地仓库中。 您可以使用git fetch命令,如下所示。

git fetch origin pull/ID/head:BRANCHNAME

git fetch origin pull/ID/head:BRANCHNAME

ID is the pull request id and BRANCHNAME is the name of the branch that you want to create. Once the branch has been created you can use git checkout to switch to that brach.

ID是请求请求的ID,而BRANCHNAME是要创建的分支的名称。 创建分支后,您可以使用git checkout切换到该分支。

guide.freecodecamp.org中有关git的其他资源 (Other Resources on git in guide.freecodecamp.org)

翻译自: https://www.freecodecamp.org/news/git-pull-explained/

git pull git

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值