简体   繁体   English

如何使用rugged来检查我的git存储库中是否存在未经修改的更改?

[英]How do I use rugged to check if there are uncommited changes in my git repository?

How do I use rugged to check whether there are uncommitted changes in my git repo? 如何使用rugged来检查我的git repo中是否有未提交的更改?

Much like How do I programmatically determine if there are uncommited changes? 就像我如何以编程方式确定是否存在未经修改的更改一样?

Wow. 哇。 This question has been dead from some time, but thought I'd throw in my 2 cents as I'm using learning/using Rugged currently. 这个问题已经有一段时间了,但是当我正在使用学习/使用Rugged时,我认为我会投入2美分。

There's a handy method Repository#diff_workdir that exists nowadays. 现在有一个方便的方法Repository#diff_workdir

Suppose you want to compare the working directory to the last commit( the equivalent of what I think of just a plain old git diff ). 假设您想要将工作目录与最后一次提交进行比较(相当于我认为只是一个普通的旧git diff )。 You can get that with this: 你可以用这个:

repo.diff_workdir(repo.last_commit)

Hope this helps someone! 希望这有助于某人!

You do it the same way. 你以同样的方式做到这一点。 Either ask status or diff whether there are changes between HEAD and the worktree. 询问状态或区分HEAD和工作树之间是否有变化。

Rugged doesn't have diff support merged in yet, so you'd have to use status. Rugged还没有合并差异支持,所以你必须使用状态。

Diff support was recently added. 最近添加了差异支持。 You can pull the latest version from github. 您可以从github获取最新版本。

a = Rugged::Tree.lookup(repo, "806999").tree
b = Rugged::Tree.lookup(repo, "a8595c").tree

diff = a.diff(b)

deltas = diff.deltas
patches = diff.patches

You can get something similar to git status using Repository#status . 您可以使用Repository#status获得类似于git status Repository#status

If you'd just like to check if there are any unstaged changes: 如果您只是想检查是否有任何未分级的更改:

repository.to_enum(:status).any?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM