How to find out the latest version of clone / fetch / pull from a GitHub repo?

Does GitHub provide the time of the last available repository pull / fetch / clone (at least for those who have write access to the repo)?

The interest in this information, of course, is explained by the desire to evaluate how safe it would be to do git push -f on a repo, which would essentially rewrite the last few commits: if there was no pull / fetch / clone, since the earliest record to be overwritten was ported to GitHub, then rewriting might be ok ...


Perhaps an example will clarify my question. For simplicity, suppose that there is only one local branch ( master ) and one remote branch ( origin/master ). (IOW, the remote repo has only one branch, and I only track it with our local branch.)

First, consider a completely local scenario: I am doing a commit, and soon realized that there was a problem with this commit. In this case, I just overwrite this commit with the correct one using git commit --amend ...

Now imagine exactly the same scenario, with the difference that, before I notice a commit problem, I push the erroneous commit to the remote relay (GitHub).

If I am the only user of this repo, I can just overwrite the commit locally as before, and then use git push -f ... to overwrite the erroneous commit in the remote repository (GitHub).

If, however, I am not the only user of this repo, the procedure described above is problematic because another user can clone or retrieve the remote (GitHub) from the repository at some point after I clicked on the erroneous commit, but before I overwritten the erroneous commit in the remote repo.

One way to minimize this feature is to check the recording of all pull, fetch and clone operations performed in the remote repo from the moment I pressed the wrong commit on it. If this record shows at least one of these operations, then this will mean that we have exactly the problematic scenario described in the previous paragraph.

If, on the other hand, there is no such operation in the record, then there is one more hope that I can rewrite the erroneous commit in the remote repo without the problematic scenario described above. (Of course, this is a race condition, so there is no 100% guarantee.)

All this, however, is based on the availability of such a record of pull, fetch, and clone operations in a remote repo. I doubt that GitHub makes such a record available, at least to those who have write access to the repo.

+4
source share
2 answers

The GitHub V3 API returns, for custom repositories :

 ... "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 may be the time of the last commit, but not necessarily the last commit on the branch where you are push --force .

However, there is no record of the last pull, fetch of clone , especially given that the upstream repo has no idea how many reverse repositories are accessing it and when.

See " Definition of" downstream "and" upstream " .

GitHub can record this information: it is an upstream repo, but manages its own infrastructure and access mechanism, so yes, it can record this access.
But I do not believe that some information is available to all users.

+1
source

Because in your problem, you sent the real intention as:

.. comes from a desire to evaluate how safe it would be to do git push -f ...

I think that a change in your workflow would make life a lot easier. I suggest doing the following:

Do not transfer non-trivial changes directly to master (basically everything you may want to change later). Once a change has landed in master , it should never be touched. 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 the need for --rebase on master . That should never have happened. There is a better technique that you might want to use. Let's say that the bug_fix branch takes some time to fix, but you also want to continue developing new_idea when testing bug fixes. Therefore, we say that we start with the following:

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

So, we want to apply the changes from cool_idea on top of bug_fix so that we can work with them in tandem. Here's how you do it:

 git checkout cool_idea git rebase --onto bug_fix master cool_idea 

Then you will look like this:

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

If you really want to use this method, I will write the steps for cleaning, if you need to add a commit or --rebase branch to bug_fix .

0
source

All Articles