问题描述
如何确定git存储库中的给定目录是否包含未经修改的提交更改?
例如。给定一个包含两个目录A和B的存储库,当且仅当git日志包含更新尚未推送到远程主服务器的A的内容的提交时,返回true。
对于上下文来说,我的用例是一个混合存储库,它有两种语言标准,我有兴趣在js目录预推动时运行linter和测试套件,只要这些文件已被更改。
您可以使用下面的解决方案。 Git会检查远程,看看提交是否存在。如果找到一个提交,那么你会得到提交,从那里我们只是得到行数。如果行数为0,则不会提交任何提交
git log HEAD --pretty = oneline --not --remotes - path | wc -l
示例
git log HEAD --pretty = oneline --not --remotes - src / A | wc -l
How to determine whether or not a given directory within a git repository contains unpushed, committed changes?
e.g. given a repository with two directories, A and B, return true if and only if the git log contains commits that updated the contents of A that have not been pushed to a remote master, yet.
For context, my use case is a hybrid repository with two language standards where I am interested in running a linter and test suite on the js directory pre-push, only if those files have been altered.
You can use the below solution. Git will check against the remote to see if the commit is there are not. If a commit is found then you will get the commit, from that we are just getting the line count. If line count is 0 no commits are found
git log HEAD --pretty=oneline --not --remotes -- path | wc -l
Example
git log HEAD --pretty=oneline --not --remotes -- src/A | wc -l
这篇关于确定git存储库中的某个目录是否包含未提交的,已提交的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!