Git的:确定分支是在合并冲突状态 [英] Git : Determine if branch is in a merge conflict state
问题描述
我写一个bash脚本,做一些自动化。该脚本的一部分涉及导航到本地回购,切换到本地的master分支,然后拉远程主更新本地主分支与最新的code。
I am writing a bash script to do some automation. Part of the script involves navigating to a local repo, switching to the local master branch, then pulling the remote master to update the local master branch with the latest code.
有谁知道,如果有一种方法,我可以编程方式确定是否拉产生了一个合并冲突,这样我可以在这一点保释,而不是执行该脚本的其余部分?
Does anyone know if there's a way I can programatically determine if the pull resulted in a merge conflict so that I can bail at that point and not execute the rest of the script?
任何帮助/信息是AP preciated,谢谢!
Any help / info is appreciated, thanks!
推荐答案
使用 git的LS-文件-u
。它打印未合并的文件。如果打印什么,有没有未合并的文件。
Use git ls-files -u
. It prints unmerged files. If it prints nothing, there are no unmerged files.
不过,虽然这对你问为问,使用 git的拉
在脚本的问题直接回答有点冒险:拉
是运行一个方便的剧本取
为你,然后(取决于你如何指挥它和/或配置了回购)可运行合并
或重订
为您服务。假设你正在写的心中都有一个特定目标的脚本,你应该最有可能被使用做更具体的事情下级的命令。例如,你可以使用混帐取
之后(如伊坦赖斯纳在评论建议)混帐合并--ff只
,以便从不的尝试合并。
However, while that's a direct answer for the question you asked "as asked", using git pull
in a script is a bit dicey: pull
is a convenience script that runs fetch
for you, and then (depending on how you direct it and/or have configured your repo) runs either merge
or rebase
for you. Given that you are writing a script that has a particular goal in mind, you should most likely be using lower-level commands that do more-specific things. For instance, you might use git fetch
followed by (as Etan Reisner suggested in a comment) git merge --ff-only
so as to never attempt a merge.
这篇关于Git的:确定分支是在合并冲突状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!