0

这是我的数据框文件,其中包含 CommitId:

CommitId
d38f7b334856ed4007fb3ec0f8a5f7499ee2f2b8
d38f7b334856ed4007fb3ec0f8a5f7499ee2f2b8
d38f7b334856ed4007fb3ec0f8a5f7499ee2f2b8
4bb968a47ce00279d6051df95bd782650700179e
c3d7ec38417ecff03d1cd3be0163e6ce07578eb3
00568c9886e739d6b5dd61b4a4326d598552fb6f
00568c9886e739d6b5dd61b4a4326d598552fb6f
00568c9886e739d6b5dd61b4a4326d598552fb6f
00568c9886e739d6b5dd61b4a4326d598552fb6f
6e062098453febbfb0169cd0af56f70f2e3fc77f
63f658918c2f4b851b0d0fffbffab4df0cfe13ca

我需要检查每个提交并将代码版本复制到另一个目录中,因此对于此示例,我需要一个目录中的每个代码版本的 11 个,因此 11 个具有不同名称的目录

我试过这个示例代码:

import os
from distutils.dir_util import copy_tree
path1='C:/Users/AQ42770/Desktop/RefactoringMiner/bin/Android-ContactPicker'
os.chdir(path1)

commande1='git worktree add C:/Users/AQ42770/Documents/commit d38f7b334856ed4007fb3ec0f8a5f7499ee2f2b8' 
os.system(commande1)

commande2='git worktree add C:/Users/AQ42770/Documents/commit1 
4bb968a47ce00279d6051df95bd782650700179e'
os.system(commande2) 

但这不切实际,因为对于这个例子我有很多提交我有 11 次提交给其他人我有 100 多次提交。所以我尝试了这段代码,但它什么也没返回:

n=1
list=["95fe00030ad97c998cd0b1b7df030dcda0db7baa","47b91018e3cb45ee0f7c3135488855554ad6617d"]
path="C:/Users/AQ42770/Documents/commit"
for n in range(0,2):
   t=path+str(n)
   os.system('git worktree add t list[n]')

PS:我将提交放在一个列表中进行测试,然后我将从数据框中读取

4

1 回答 1

0

假设数据文件是C:/Users/AQ42770/Desktop/mydata.txt.

import os
import re

wortreebase = 'C:/Users/AQ42770/Documents/'
mydata = 'C:/Users/AQ42770/Desktop/mydata.txt'
gitdir = 'C:/Users/AQ42770/Desktop/RefactoringMiner/bin/Android-ContactPicker/.git'

# find all commits
with open(mydata) as f:
    commits = re.findall(r'[0-9a-f]{40}', f.read())

for i, commit in enumerate(commits):
    # name the worktree
    worktree = wortreebase + '%s_%s' % (i, commit))
    # create the worktree
    cmd = 'git --git-dir=%s worktree add %s %s' % (gitdir, worktree, commit)
    os.system(cmd)
于 2019-06-11T03:51:03.450 回答