如何找到与不在git控制下的项目修订相对应的提交? [英] How to find a commit that corresponds to a project revision that is not under git control?

查看:76
本文介绍了如何找到与不在git控制下的项目修订相对应的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下情况:

我有一个项目的源代码(几个文件夹和文件)。不幸的是,源代码不受版本控制。
但是,这个项目有一个远程git仓库。



如何在git仓库中找到与我的项目修订相对应的提交?b / b>




我的蛮力方法是:克隆存储库,在不同的提交中签出并将签出的文件与我的文件。



是否有更优雅的方式来找到提交?

解决方案

我认为两种明显的方法不可用(查看VERSIONS / README文件,或者在下载的tar.gz文件中查找版本号)。

您可以尝试以下操作。它会显着更快,因为它避免了结帐。这只有在你没有以任何方式修改源代码的情况下才有效。


  1. git init 新存储库

  2. git add 整个源代码副本,然后 git commit

  3. git rev-parse HEAD ^ {tree} 获取树 - 代码对应的$ <$>

现在 git clone 远程,然后在该回购中执行一个脚本,如

 #这应该是上面给出的tree-SHA 
needle = ABCDEF12345
#如果您有猜测,您可以将其限制为HEAD或分支
for rev in $(git rev-list --all)
do
if [$(git rev-parse $ {rev} ^ {tree})= $ {needle}]
然后
echoSha $ {rev} matches
fi
done

一旦你有一个匹配的SHA,你可以尝试使用 git tags --points-at


获得它的发行版

Consider the following situation:

I have the source code of a project (several folders and files). Unfortunately, the source code is not under version control. However, there is a remote git repository for this project.

How can I find the commit in the git repository, that corresponds to my revision of the project?


My brute-force approach would be: clone the repository, checkout at different commits and compare the checked out files with my files.

Is there a more elegant way to find the commit?

解决方案

I presume the two obvious approaches aren't available (looking at a VERSIONS/README file, or looking for a version number in the tar.gz file you downloaded).

You could try the following. It will be significantly faster because it avoids the checkout. It would only work if you have not modified the source in any way.

  1. git init a new repository
  2. git add the entirety of your copy of the source and then git commit
  3. git rev-parse HEAD^{tree} to get the tree-SHA the code corresponds to

Now git clone the remote, and then in that repo execute a script like

# This should be the tree-SHA given by the above 
needle=ABCDEF12345
# you could limit this to just HEAD or a branch if you had a guess 
for rev in $(git rev-list --all)
do
   if [ $(git rev-parse ${rev}^{tree}) = ${needle} ]
   then
      echo "Sha ${rev} matches"
   fi
done

Once you have a matching SHA you could try to get a release for it with git tags --points-at

这篇关于如何找到与不在git控制下的项目修订相对应的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆