如何检查远程(原始)Git 存储库上的更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2514270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:07:17  来源:igfitidea点击:

How to check for changes on remote (origin) Git repository?

git

提问by Lernkurve

Question

What are the Git commands to do the following workflow?

执行以下工作流程的 Git 命令是什么?

Scenario

设想

I cloned from a repository and did some commits of my own to my local repository. In the meantime, my colleagues made commits to the remote repository. Now, I want to:

我从一个存储库克隆,并做了一些我自己的提交到我的本地存储库。与此同时,我的同事向远程存储库提交了提交。现在,我想:

  1. Check whether there are any new commits from other people on the remote repository, i.e. origin?

  2. Say there were 3 new commits on the remote repository since my last pull, I would like to diff the remote repository's commits, i.e. HEAD~3with HEAD~2, HEAD~2with HEAD~1and HEAD~1with HEAD.

  3. After knowing what changed remotely, I want to get the latest commits from the others.

  1. 检查远程存储库上是否有其他人的新提交,即origin

  2. 假设自上次拉取以来远程存储库上有 3 个新提交,我想比较远程存储库的提交,即 HEAD~3with HEAD~2HEAD~2with HEAD~1HEAD~1with HEAD

  3. 在知道远程更改了什么之后,我想从其他人那里获得最新的提交。

My findings so far

到目前为止我的发现

For step 2: I know the caret notation HEAD^, HEAD^^etc. and the tilde notation HEAD~2, HEAD~3etc.

对于第2步:我知道插入符号的符号HEAD^HEAD^^等和波浪符号HEAD~2HEAD~3等等。

For step 3: That is, I guess, just a git pull.

对于第 3 步:也就是说,我想,只是一个git pull.

回答by Alan Haggai Alavi

You could git fetch originto update the remote branch in your repository to point to the latest version. For a diff against the remote:

您可以git fetch origin更新存储库中的远程分支以指向最新版本。对于遥控器的差异:

git diff origin/master

Yes, you can use caret notation as well.

是的,您也可以使用插入符号。

If you want to accept the remote changes:

如果要接受远程更改:

git merge origin/master

回答by Rajani Karuturi

git remote update && git status 

Found this on the answerto Check if pull needed in Git

发现这个对答案,以检查是否需要拉Git中

git remote updateto bring your remote refs up to date. Then you can do one of several things, such as:

  1. git status -unowill tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.

  2. git show-branch *masterwill show you the commits in all of the branches whose names end in master (eg master and origin/master).

If you use -vwith git remote updateyou can see which branches got updated, so you don't really need any further commands.

git remote update使您的远程引用保持最新。然后,您可以执行以下几项操作之一,例如:

  1. git status -uno会告诉您正在跟踪的分支是在前面、后面还是已经发散。如果它什么也没说,本地和远程是一样的。

  2. git show-branch *master将向您显示名称以 master 结尾的所有分支中的提交(例如 master 和 origin/master)。

如果你使用-vwithgit remote update你可以看到哪些分支得到了更新,所以你真的不需要任何进一步的命令。

回答by jag

A good way to have a synthetic view of what's going on "origin" is:

综合了解“起源”正在发生的事情的一个好方法是:

git remote show origin

回答by Paul 501

I just use

我只是用

git remote update
git status

The latter then reports how many commits behind my local is. (if Any)

后者然后报告我的本地后面有多少提交。(如果有的话)

then

然后

git pull origin master

to bring my local up to date :)

使我的本地更新:)

回答by iceCode

My regular question is rather "anything new or changed in repo" so whatchangedcomes handy. Found it here.

我的常规问题是“回购中的任何新内容或更改”,所以whatchanged很方便。在这里找到

git whatchanged origin/master -n 1

回答by Lernkurve

One potential solution

一种潜在的解决方案

Thanks to Alan Haggai Alavi's solutionI came up with the following potential workflow:

感谢Alan Haggai Alavi 的解决方案,我想出了以下潜在的工作流程:

Step 1:

第1步:

git fetch origin

Step 2:

第2步:

git checkout -b localTempOfOriginMaster origin/master
git difftool HEAD~3 HEAD~2
git difftool HEAD~2 HEAD~1
git difftool HEAD~1 HEAD~0

Step 3:

第 3 步:

git checkout master
git branch -D localTempOfOriginMaster
git merge origin/master

回答by Hymanal

git statusnot always shows the difference between master and origin/master even after a fetch. If you want the combination git fetch origin && git statusto work, you need to specify the tracking information between local branch and origin:

git status即使在获取之后,也并不总是显示 master 和 origin/master 之间的差异。如果你想让组合git fetch origin && git status生效,你需要指定本地分支和原点之间的跟踪信息:

# git branch --set-upstream-to=origin/<branch> <branch>

For master branch:

对于主分支:

git branch --set-upstream-to=origin/master master

回答by raphael

since it has not been suggested so far... and i find it quite useful...

因为到目前为止还没有建议......而且我觉得它非常有用......

i simply use

我只是使用

git fetch origin

to fetch the remote changes, and then i view both local and pending remote commits (and their associated changes) with the nice gitk tool (https://git-scm.com/docs/gitk) involving the --all argument like

获取远程更改,然后我使用包含 --all 参数的漂亮 gitk 工具(https://git-scm.com/docs/gitk)查看本地和挂起的远程提交(及其相关的更改)

gitk --all