[英]How to check for changes on remote (origin) Git repository
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:现在,我想:
Check whether there are any new commits from other people on the remote repository, ie origin
?检查远程存储库上是否有其他人的新提交,即origin
?
Say there were three new commits on the remote repository since my last pull, I would like to diff the remote repository's commits, ie HEAD~3
with HEAD~2
, HEAD~2
with HEAD~1
and HEAD~1
with HEAD
.假设自上次拉取以来远程存储库上有三个新提交,我想比较远程存储库的提交,即HEAD~3
与HEAD~2
, HEAD~2
与HEAD~1
和HEAD~1
与HEAD
。
After knowing what changed remotely, I want to get the latest commits from the others.在知道远程更改了什么之后,我想从其他人那里获得最新的提交。
My findings so far到目前为止我的发现
For step 2: I know the caret notation HEAD^
, HEAD^^
etc. and the tilde notation HEAD~2
, HEAD~3
, etc.对于第 2 步:我知道插入符号HEAD^
、 HEAD^^
等和波浪符号HEAD~2
、 HEAD~3
等。
For step 3: That is, I guess, just a git pull
.对于第 3 步:也就是说,我想,只是一个git pull
。
You could git fetch origin
to update the remote branch in your repository to point to the latest version.您可以git fetch origin
更新存储库中的远程分支以指向最新版本。 For a diff against the remote:对于遥控器的差异:
git diff origin/master
Yes, you can use caret notation as well.是的,您也可以使用插入符号。
If you want to accept the remote changes:如果要接受远程更改:
git merge origin/master
git remote update && git status
Found this on the answer to Check if pull needed in Git在检查是否需要在 Git 中拉取的答案中找到了这个
git remote update
to bring your remote refs up to date.git remote update
使您的远程引用保持最新。 Then you can do one of several things, such as:然后,您可以执行以下几项操作之一,例如:
git status -uno
will tell you whether the branch you are tracking is ahead, behind or has diverged.git status -uno
会告诉您正在跟踪的分支是在前面、后面还是已经发散。 If it says nothing, the local and remote are the same.如果它什么也没说,本地和远程是一样的。
git show-branch *master
will show you the commits in all of the branches whose names end in master (eg master and origin/master).git show-branch *master
将向您显示名称以 master 结尾的所有分支中的提交(例如 master 和 origin/master)。If you use
-v
withgit remote update
you can see which branches got updated, so you don't really need any further commands.如果您将-v
与git remote update
一起使用,您可以查看哪些分支已更新,因此您实际上不需要任何其他命令。
综合了解“起源”正在发生的事情的一个好方法是:
git remote show origin
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 :)使我的本地更新:)
One potential solution一种潜在的解决方案
Thanks to Alan Haggai Alavi's solution I 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
git status
does not always show the difference between master and origin/master even after a fetch.即使在 fetch 之后, git status
也不总是显示 master 和 origin/master 之间的区别。
If you want the combination git fetch origin && git status
to work, you need to specify the tracking information between the local branch and origin:如果想让组合git fetch origin && git status
起作用,则需要指定本地分支和原点之间的跟踪信息:
# git branch --set-upstream-to=origin/<branch> <branch>
For the master branch:对于主分支:
git branch --set-upstream-to=origin/master master
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.