git 相当于 svn status -u
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1138990/
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
git equivalent of svn status -u
提问by hyperboreean
What's the git equivalent of svn status -u
or more verbose svn status --show-updates
.
The svn status --show-updates
command shows the updates that the svn update
command will bring from the server.
什么是 git 等价物svn status -u
或更详细的svn status --show-updates
. 该svn status --show-updates
命令显示该svn update
命令将从服务器带来的更新。
Thanks!
谢谢!
采纳答案by tialaramex
I can't think of a way to do it without actually fetching the updates (maybe someone else will). Assuming you are on the default branch "master" and the upstream from which these hypothetical updates will come is the default remote "origin", try....
如果不实际获取更新(也许其他人会),我想不出一种方法。假设您在默认分支“master”上,并且这些假设更新将来自的上游是默认的远程“源”,请尝试....
git fetch
git log --name-only ..origin/master
Note the double dots .. not a single dot or an elipsis1.
注意双点……不是单点或省略号1。
This will give you a list of log entries for changes that are only upstream, with the filenames affected, you can alter the parameters to git log to get more or less information.
这将为您提供仅上游更改的日志条目列表,文件名受到影响,您可以将参数更改为 git log 以获取更多或更少的信息。
NB in git "fetching" these updates isn't the same as applying them to your local branch. You no doubt already know how to do that with git pull.
注意 git “获取”这些更新与将它们应用到本地分支不同。毫无疑问,您已经知道如何使用 git pull 做到这一点。
1As for where do the double dots come from, name1..name2
indicates a range. If name1
is omitted, HEAD
is used in its place. This syntax refers to all commits reachable from name2
back to, but not including, HEAD
. ["Git from the bottom up"]
1至于双点从何而来,name1..name2
表示一个范围。如果name1
省略,HEAD
则在其位置使用。此语法指的是从name2
后到但不包括可到达的所有提交HEAD
。[ “自下而上的 Git”]
回答by Jakub Nar?bski
Both Martinho Fernandesand tialaramexanswers correctly describe what you need to do. Let me describe whyit is the way it is.
无论Martinho费尔南德斯和tialaramex答案正确地描述你需要做什么。让我描述一下为什么会这样。
Subversion
颠覆
Subversionis centralizedversion control system. It means that it operates in client--server fashion: server stores all the data about version (repository), client has only working directory (files) plus some administrative and helper data. This means that for most commands client has to contact server. This also means that there are many commands asking about state of repository on server, or server configuration, like "svn status --show-updates
" in question.
Subversion是集中式版本控制系统。这意味着它以客户端-服务器方式运行:服务器存储有关版本(存储库)的所有数据,客户端只有工作目录(文件)以及一些管理和帮助数据。这意味着对于大多数命令客户端必须联系服务器。这也意味着有许多命令询问服务器上存储库的状态或服务器配置,例如svn status --show-updates
有问题的“ ”。
(Sidenote: one helper data that Subversion stores on client are the "pristine" version of files, which means that checking for changes you did doesn't require to connect to server (which is slow)... but it also means that SVN checkout might be larger than Git repository).
(旁注:Subversion 在客户端存储的一个辅助数据是文件的“原始”版本,这意味着检查您所做的更改不需要连接到服务器(这很慢)……但这也意味着 SVN checkout 可能比 Git 存储库大)。
"svn update" (required before commit if repository has any changes in given branch) downloads last version from remote andmerges (tries to merge) changes you did with changes from remote. IMHO this update-before-commit workflow is not very conductive.
“svn update”(如果存储库在给定分支中有任何更改,则在提交之前需要)从远程下载最新版本并合并(尝试合并)您对远程更改所做的更改。恕我直言,这个提交前更新的工作流程不是很有效。
Git
吉特
Gitis distributedversion control system. This means that it operates on peer-to-peer fashion: each "client" has all the data about versions (full repository). The central repository is central only because of social convention and not technical limitations. This means that when contacting other remote repository the number of commands "executed remotely" is very small. You can ask for references (heads aka. branches and tags) with "git ls-remote" (and "git update show"), you can pull (get) or push (publish) data with "git fetch" (or "git remote update") / "git push", and if server is configured to allow it you can get snapshot of state of remote repository with "git archive --remote".
Git是分布式版本控制系统。这意味着它以点对点的方式运行:每个“客户端”都拥有有关版本的所有数据(完整存储库)。中央存储库是中央的只是因为社会惯例而不是技术限制。这意味着当联系其他远程存储库时,“远程执行”的命令数量非常少。您可以使用“git ls-remote”(和“git update show”)请求引用(也称为分支和标签),您可以使用“git fetch”(或“git远程更新”)/“git push”,如果服务器配置为允许它,您可以使用“git archive --remote”获取远程存储库状态的快照。
So to examine commits which are in remote repository but are not present in your repository you have to download data to your machine. But "git pull" is in fact nothing more than "git fetch" which downloads data and "git merge" which merges it (with a bit of sugar to prepare commit messages and choose which branch to merge). You can then use 'git fetch" (or "git remote update"), examine newly brought commits with "git log" and "gitk" (not being limited to fixed output), and then if everything is all right merge changes with "git merge".
因此,要检查远程存储库中但不存在于您的存储库中的提交,您必须将数据下载到您的机器上。但是“git pull”实际上只不过是下载数据的“git fetch”和合并数据的“git merge”(用一点糖来准备提交消息并选择要合并的分支)。然后,您可以使用“git fetch”(或“git remote update”),使用“git log”和“gitk”(不限于固定输出)检查新提交的提交,然后如果一切正常,则将更改与“ git 合并”。
This is not specific to Git, but to all distributed version control systems, although the way SCM presents fetched but unmerged data might differ (Git uses remote-tracking branches in 'remote/<remotename>/*' namespace, Mercurial from what I understand, uses unnamed heads).
这并非特定于 Git,而是所有分布式版本控制系统,尽管 SCM 呈现已获取但未合并的数据的方式可能有所不同(Git 在 'remote/<remotename>/*' 命名空间中使用远程跟踪分支,据我了解 Mercurial , 使用未命名的头)。
HTH
HTH
回答by R. Martinho Fernandes
If you fetch:
如果你取:
git fetch <remote>
instead of pulling:
而不是拉:
git pull <remote>
from the remote, you can then inspect what changed with git log
. To apply the changes:
然后,您可以从遥控器检查更改的内容git log
。要应用更改:
git merge <remote>/<remote-branch>
回答by nickgrim
You can use git ls-remote
to list the SHA of references in a remote repository; so, you can see if there are any changes by comparing the output of:
您可以使用git ls-remote
列出远程存储库中引用的 SHA;因此,您可以通过比较以下输出来查看是否有任何更改:
$ git show-ref origin/master # <-- Where this repo thinks "origin/master" is
5bad423ae8d9055d989a66598d3c4473dbe97f8f refs/remotes/origin/master
$ git ls-remote origin master # <-- Where "origin" thinks "master" is
060bbe2125ec5e236a6c6eaed2e715b0328a9106 refs/heads/master
If they differ, then there are changes to fetch:
如果它们不同,则 fetch 会发生变化:
$ git remote update
Fetching origin
...
From github.com:xxxx/yyyy
5bad423..060bbe2 master -> origin/master
回答by Malo
For me, just to display files that will changed, it's :
对我来说,只是为了显示会改变的文件,它是:
git fetch (1)
git diff --name-only ..origin/master (2)
- Fetches changes in the Git "database" (the .git directory only) and do not alter files.
- Shows names of files that will changed after a merge
- 获取 Git“数据库”(仅限 .git 目录)中的更改并且不更改文件。
- 显示合并后将更改的文件的名称
To updates files (not only Git "database") do a git merge
要更新文件(不仅是 Git“数据库”),请执行 git merge
回答by zbacsi
Gits gives us more tools to check an "update". First you have to "download" the up-to-date state of the repository:
Gits 为我们提供了更多工具来检查“更新”。首先,您必须“下载”存储库的最新状态:
git fetch
Now you can get the list of the changed files:
现在您可以获取已更改文件的列表:
git log --name-status ..origin/master
Additionaly, you can see the full list of changes with diff:
另外,您可以使用 diff 查看完整的更改列表:
git diff ..origin/master
Meaning of the starting letters are: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B)
起始字母的含义是:已添加 (A)、已复制 (C)、已删除 (D)、已修改 (M)、已重命名 (R)、已更改 (T)、未合并 (U)、未知 (X) 或已经有他们的配对破碎(B)
回答by Milimetric
git fetch && git log --name-status ..origin/master
does indeed show the logs that would be merged. However, it also pulls the changes. It's not technically possible to do the same exact thing as svn status -u
, but git fetch
is so fast that usually it shouldn't matter
git fetch && git log --name-status ..origin/master
确实显示了将被合并的日志。然而,它也拉动了变化。在技术上不可能做与 完全相同的事情svn status -u
,但git fetch
速度太快以至于通常无关紧要
If you absolutely need the log before fetching, the only way would be to connect (SSH or equivalent) into the remote and issue git log
there.
如果您在获取之前绝对需要日志,唯一的方法是连接(SSH 或等效的)到远程并git log
在那里发出。