简体   繁体   English

如何从GitHub仓库中找到最新的clone / fetch / pull?

[英]How do find out latest clone/fetch/pull from a GitHub repo?

Does GitHub make the time of a repo's latest pull/fetch/clone available (at least to those with write-access to the repo)? GitHub是否可以使repo的最新pull / fetch / clone可用(至少对那些对repo有写访问权限的人)?

The interest in this information, of course, comes from wanting to gauge how safe it would be to do a git push -f on the repo that would essentially overwrite the last few commits: if no pull/fetch/clone has happened since the earliest commit-to-be-overwritten was pushed to GitHub, then the overwrite may be OK... 当然,对这些信息的兴趣来自于想要评估在repo上执行git push -f安全性,这将基本上覆盖最后几次提交:如果最早没有发生pull / fetch / clone提交被覆盖被推送到GitHub,然后覆盖可能没问题......


Perhaps an example will clarify my question. 也许一个例子将澄清我的问题。 For simplicity, let's assume that there's only one local branch ( master ) and one remote branch ( origin/master ). 为简单起见,我们假设只有一个本地分支( master )和一个远程分支( origin/master )。 (IOW, the remote repo has only one branch, and I am tracking it with our only local branch.) (IOW,远程仓库只有一个分支,我用我们唯一的本地分支跟踪它。)

First consider a completely local scenario: I make a commit, and shortly after realize that there was a problem with this commit. 首先考虑一个完全本地的场景:我做了一个提交,不久之后意识到这个提交有问题。 In this case, I just overwrite this commit with the correct one using git commit --amend ... . 在这种情况下,我只使用git commit --amend ... 覆盖正确的git commit --amend ...

Now imagine exactly the same scenario, with the difference that, before noticing the problem with the commit, I push the faulty commit to the remote (GitHub) repo. 现在想象完全相同的场景,区别在于,在注意到提交问题之前,我将错误提交推送到远程(GitHub)repo。

If I am the only user of this repo, then I can simply overwrite the commit locally as before, and then use git push -f ... to overwrite the faulty commit in the remote (GitHub) repo. 如果我是这个repo的唯一用户,那么我可以像以前一样在本地覆盖提交,然后使用git push -f ...来覆盖远程(GitHub)repo中的错误提交。

If, however, I am not the only user of this repo, the above procedure is problematic, because a different user could have cloned or fetched from the remote (GitHub) repo at some point after I pushed the faulty commit, but before I overwrote the faulty commit in the remote repo. 但是,如果我不是这个repo的唯一用户,那么上面的过程是有问题的,因为在推送错误的提交之后的某个时刻,在我覆盖之前,不同的用户可以从远程(GitHub)repo克隆或获取远程仓库中的错误提交。

One way to minimize this possibility is to examine a record of all the pull, fetch, and clone operations performed on the remote repo since the time I pushed the faulty commit to it. 最小化这种可能性的一种方法是检查自从我将错误提交推送到远程仓库以来在远程仓库上执行的所有pull,fetch和clone操作的记录。 If this record shows at least one of such operations, then it would mean that we have precisely the problematic scenario described in the previous paragraph. 如果此记录至少显示其中一个此类操作,那么这意味着我们确实存在前一段中描述的有问题的情况。

If, on the other hand, the record shows no such operation, then there is still some hope that I could overwrite the faulty commit in the remote repo without incurring in the problematic scenario described earlier. 另一方面,如果记录显示没有这样的操作,那么仍然有一些希望我可以覆盖远程仓库中的错误提交而不会引起前面描述的有问题的情况。 (Of course, this is a race condition, so there's no 100% guarantee.) (当然,这是竞争条件,所以没有100%保证。)

All this, however, is predicated on the availability of such record of pull, fetch, and clone operations on the remote repo. 然而,所有这些都取决于远程仓库上的拉,取和克隆操作记录的可用性。 I'm question is whether GitHub makes such record available, at least to those with write-access to the repo. 我怀疑GitHub是否提供了这样的记录,至少对那些具有对repo的写访问权限的人来说是这样。

The GitHub V3 API does return, for a user's repositories : 对于用户的存储库 ,GitHub V3 API确实返回:

...
    "pushed_at": "2011-01-26T19:06:43Z",
    "created_at": "2011-01-26T19:01:12Z",
    "updated_at": "2011-01-26T19:14:43Z"
  }

The " pushed_at " field might be the time of the last commit, but not necessarily the last commit on the branch on which you are about to push --force . pushed_at ”字段可能是上次提交的时间,但不一定是您要push --force的分支上的最后一次提交push --force

However, there is no record of the latest pull, fetch of clone , especially considering that an upstream repo has no idea of how many downstream repos are accessing it and when. 然而, 没有记录最新的拉取,克隆 ,特别是考虑到上游回购不知道有多少下游回购正在访问它以及何时访问它。

See " Definition of “downstream” and “upstream” ". 参见“ 下游”和“上游”的定义

GitHub could record those information: it is an upstream repo, but manages its own infrastructure and access mechanism, so yes, it could record said access. GitHub可以记录这些信息:它是一个上游仓库,但管理自己的基础设施和访问机制,所以是的,它可以记录所述访问。
But I don't believe that kind of information is available at all for users to see. 但我不相信用户可以看到那种信息。

Because in your issue you posted the real intent as being: 因为在您的问题中,您发布的真实意图是:

..comes from wanting to gauge how safe it would be to do a git push -f... ..想要衡量一下git push -f的安全性...

I think a change to your workflow would make life much easier. 我认为改变工作流程会让生活变得更轻松。 I'd suggest doing the following: 我建议做以下事情:

Don't commit non-trivial changes directly to master (basically anything that you might want to change later). 不要直接向master提交非平凡的更改(基本上您可能希望稍后更改)。 Once a change has been landed in master it should never ever be touched. 一旦改变已经mastermaster它就永远不会被触及。 Here is an example: 这是一个例子:

# assuming starting on master branch
git checkout -b new_cool_idea
# commit a few things
git push origin new_cool_idea
# realize there was a bug preventing you from finishing the
# implementation of new_cool_idea
git checkout -b cool_idea_bug_fix master
# commit the bug fix
# if you have any reviewers, push to remote
git push origin cool_idea_bug_fix
# when bug fix is all good, cleanup and finish new_cool_idea
git checkout master
git merge cool_idea_bug_fix
git branch -d cool_idea_bug_fix
git push origin :cool_idea_bug_fix
git checkout new_cool_idea
git rebase master
# may possibly have conflicts, go ahead and resolve
# now finish implementing new_cool_idea
# if you only want to update one remote branch add <remote> <branch>
# otherwise all remotes will be updated
git push -f <remote> <branch>

This should help prevent needing to --rebase on master . 这应该有助于防止需要--rebase on master Which again shouldn't ever happen. 这也不应该发生。 There is a more advanced technique that you might want to use. 您可能希望使用更先进的技术。 Say the bug_fix branch takes a little while to fix, but you also want continue developing new_idea while testing out the bug fix. 假设bug_fix分支需要一些时间来修复,但您还需要在测试错误修复时继续开发new_idea So say we start with the following: 所以说我们从以下开始:

o-----o-----o             master
      |      \
      |       o-----o     bug_fix
       \
        o-----o           cool_idea

So what we want is to apply the changes from cool_idea on top of bug_fix so we can work with them in tandem. 所以,我们要的是从应用更改cool_idea之上bug_fix ,所以我们可以在串联和他们合作。 Here's how you'd do that: 这是你如何做到这一点:

git checkout cool_idea
git rebase --onto bug_fix master cool_idea

Then you're history would look like the following: 然后你的历史将如下所示:

o-----o-----o                   master
             \
              o-----o           bug_fix
                     \
                      o-----o   cool_idea

If you would really consider using this method then I'll write up the steps for cleanup if you need to add a commit to or --rebase the branch bug_fix . 如果您真的考虑使用此方法,那么如果您需要添加提交或--rebase分支bug_fix我将编写清理步骤。

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

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