Git中是否有“ git pull --dry-run”选项?

是否存在诸如git pull之类的东西,以查看在它们弄乱我的工作树之前如何将它们合并?

现在我正在做:

git fetch origin && git merge --no-commit --no-ff

我没有在手册页中看到与“ git-pull”相关的任何内容。

为了澄清起见,我只需要在Ant脚本中进行部署即可查看在执行git pull时是否存在冲突,然后退出退出构建,使部署失败,并使该目录树与git pull之前的目录树相同。

Danila Ladner asked 2019-10-15T14:51:43Z
6个解决方案
50 votes

如果合并失败,我始终依靠Git的固有功能来带回我。

要估算合并的方式,可以像下面这样开始:

$ 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

如果事情没有按计划进行,请查看您的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}
rynmrtn answered 2019-10-15T14:52:12Z
28 votes

您需要先获取以更新您的本地来源/母版

git fetch origin

然后你可以这样做:

git diff --name-only origin/master

将列出已更改的文件。

git diff origin/master directory_foo/file_bar.m

将逐行列出文件directory_foo / file_bar.m的差异。

GayleDDS answered 2019-10-15T14:52:57Z
15 votes

您可以通过从当前分支中创建一个新的一次性分支并在那里进行git pull来获得所需的效果。 如果您对结果不满意,则原始分支是完整的。

gcbenison answered 2019-10-15T14:53:26Z
8 votes
# 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
warden answered 2019-10-15T14:53:47Z
2 votes

由于拉动意味着合并,因此如果脚本检测到存在任何冲突并且合并失败,我将继续运行git merge --abort

kostix answered 2019-10-15T14:54:13Z
0 votes

请参阅我在类似问题中的回答:

如何在不进行提取的情况下预览git-pull?

转到~/.gitconfig文件:

[alias]
        diffpull=!git fetch && git diff HEAD..@{u}
Andy P answered 2019-10-15T14:54:54Z
translate from https://stackoverflow.com:/questions/17222440/is-there-a-git-pull-dry-run-option-in-git