确定git merge / pull是否在Windowsbatch文件中进行了任何更改

时间:2016-03-23 10:44:52

标签: git

如何在Windows批处理文件中使用git.exe来提取更改并确定是否对我的工作副本进行了任何更改?无论是否进行了更改,pull和merge似乎都会返回退出代码0以获得“成功”。

我已经通过将stdout重定向到临时文件并将其与FC与包含“已经是最新的”的文件进行比较来完成此操作。这有效,但似乎是一个大黑客。还有更好的方法吗?

这是一个脚本,它提取远程更改,构建,运行单元测试然后推送。在推送之前,我想检查是否有其他人在我的脚本运行时推送了更改,如果是,请执行构建并再次运行测试。

1 个答案:

答案 0 :(得分:0)

  

如何在Windows批处理文件中使用git.exe来提取更改并确定是否对我的工作副本进行了任何更改

你可以这样做:

# update the local repo with changes from the remote
git fetch --all -prune

# check to see if there is a difference between your local branch and the remote branch

git log <branch>...origin/<branch>

如果您发现任何更改,则表示您不是最新的

另一种方式:

# update the local repo
git fetch --all --prune

# compare the 2 commits to see if there are any new commits
# the commands will return SHA-1 simply compare them
git rev-parse origin/dev
git rev-parse dev