Git 中是否有“git pull --dry-run”选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17222440/
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
Is there a "git pull --dry-run" option in Git?
提问by Danila Ladner
Is there such a thing as git pull --dry-run
to see how stuff will be merged before it messes up my working tree?
有没有这样的事情git pull --dry-run
可以在东西弄乱我的工作树之前查看它是如何合并的?
Right now I am doing:
现在我正在做:
git fetch origin && git merge --no-commit --no-ff
I did not see anything in the man page for 'git-pull' related to it.
我在手册页中没有看到任何与“git-pull”相关的内容。
To clarify, I just need it in an Ant script for deployment to see if there are conflicts when doing git pull
, then back off exit out of build, fail deployment and leave that directory tree the same it was before git pull
.
澄清一下,我只需要它在 Ant 脚本中进行部署,以查看执行时是否存在冲突git pull
,然后退出退出构建,部署失败并保持该目录树与之前相同git pull
。
采纳答案by rynmrtn
I have always relied on the inherent abilities of Git to get me back if a merge fails.
如果合并失败,我一直依靠 Git 的固有能力让我回来。
To estimate how the merge might occur, you can start like you did with:
要估计合并可能如何发生,您可以像这样开始:
$ git fetch origin branch # Fetch changes, but don't merge
$ git diff HEAD..origin/branch # Diff your current head to the fetched commit
... personal judgement of potential merge conflicts ...
$ git merge origin/branch # merge with the fetched commit
If things did not go as planned, look at your reflog
and reset back to your desired state:
如果事情没有按计划进行,请查看您的reflog
并重置回您想要的状态:
$ git reflog
...
abc987 HEAD@{0}: merge activity
b58aae8 HEAD@{1}: fetch origin/branch
8f3a362 HEAD@{2}: activity before the fetch
...
$ git reset --hard HEAD{2}
回答by GayleDDS
You will need to fetch first to update your local origin/master
您需要先获取以更新您的本地源/主
git fetch origin
Then you can do:
然后你可以这样做:
git diff --name-only origin/master
Will list the files that have changed.
将列出已更改的文件。
git diff origin/master directory_foo/file_bar.m
Will list the line by line diff of file directory_foo/file_bar.m.
将逐行列出文件 directory_foo/file_bar.m 的差异。
回答by gcbenison
You can get the effect you want by creating a new throw-away branch from your current one and doing the git pull
there. If you're unhappy with the results, the original branch is intact.
您可以通过从当前分支创建一个新的一次性分支并在git pull
那里执行操作来获得所需的效果。如果您对结果不满意,则原始分支完好无损。
回答by warden
# fetch new commits from origin
$ git fetch
# check what are the differences and judge if safe to apply
$ git diff origin/master
# actually merge the fetched commits
$ git pull
回答by kostix
Since pulling implies merging, I'd go with running git merge --abort
if your script detects there were any conflicts and merging failed.
由于拉动意味着合并,git merge --abort
如果您的脚本检测到存在任何冲突并且合并失败,我会继续运行。
回答by Andy P
See my answer in this similar question:
请参阅我在这个类似问题中的回答:
How to preview git-pull without doing fetch?
this goes to the ~/.gitconfig
file:
这转到~/.gitconfig
文件:
[alias]
diffpull=!git fetch && git diff HEAD..@{u}