【问题标题】:How to generate multiple folders from git worktree command?如何从 git worktree 命令生成多个文件夹?
【发布时间】:2019-06-10 20:30:31
【问题描述】:

这是我的数据框文件,其中包含 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:我先将提交放在一个列表中进行测试,然后我会从数据帧中读取

【问题讨论】:

    标签: python git cmd git-worktree


    【解决方案1】:

    假设数据文件是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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 2014-12-25
      • 2019-09-12
      • 2020-12-09
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多