我会尽量简单.
让我们走:
我们有一个大的git回购,其中包括3个文件夹为不同的项目:
主回购中的文件夹结构:
existing_repo
├── .net_is_dir
├── java_is_dir
└── android_is_dir对于java,每一期都有根目录中的分支。
对于android,每一期,我们都继承了"android“分支的分支。在gitlab结构中,下一步是:
回购中的分支结构
existing_repo
├── .net_dev
├── .net_qa
|
├── java_dev
├── java_qa
├── java_issue_1
├── java_issue_n
|
├── android_dev
├── android_qa
└── android
├─ android_issue_1
└─ android_issue_n任务是文本:
我觉得我的工作狂是不真实的
1)在新的特定回购中导入现有的回购,移动dirs,并删除un有用->导致:
每个项目将包含所有的旧项目,回购将是大的。
2)使用所需的分支创建新的repos,只需将文件从适当的dirs复制到新的分支并提交->导致
没有历史,回购规模很小
也许你会建议我一些新的想法?
发布于 2016-07-09 17:10:35
我们试试看。这是一个有点实验性的,将需要你跳进去。请原谅我在下面使用"dotnet“而不是".net”。
$ cp -r existing_repo dotnet_newrepo # Get a copy of the existing repo. The new directory will ultimately be the repo for dotnet.
$ cd dotnet_newrepo # Go to the new directory for dotnet.
$ git remote rm origin # Remove the "origin" remote. Do this for all remotes.
$ cd .. # Go back.
$ cp -r dotnet_newrepo java_newrepo # Get a copy for java (without remotes).
$ cp -r dotnet_newrepo android_newrepo # Get a copy for android (without remotes).现在,您有三个git,"dotnet_newrepo“、"java_newrepo”、"android_newrepo",它们与您现有的回购完全一样,只是没有遥控器。下一步。
$ cd dotnet_newrepo
$ git filter-branch --subdirectory-filter dotnet_is_dir -- --all
$ cd ..
$ cd java_newrepo
$ git filter-branch --subdirectory-filter java_is_dir -- --all
$ cd ..
$ cd android_newrepo
$ git filter-branch --subdirectory-filter android_is_dir -- --all
$ cd ..上面的每个git filter-branch命令将遍历回购的所有分支(因为--all)并重写它们的历史,但是.
只需查看与给定子目录有关的历史记录。结果将包含该目录(只有该目录)作为其项目根。
(来自git-过滤器-分支文档)
换句话说,子目录的内容将转到repo的根目录,git历史记录将被重写,因此它将只包含与该子目录相关的历史记录,该子目录的内容最终将是根目录的新内容和唯一内容。
按照上面描述的步骤,您仍然应该在每个回购中拥有所有分支(都带有重写的历史记录)。对于每个回购,您应该删除不相关的分支,并根据您的新约定重命名相关分支。如果分支的数量真的很大,您可以使用一个脚本来完成这个任务。最后,在为每个新回购修复分支并创建相应的远程回购(例如,在GitLab中)之后,您可以将其添加为远程并随意推送。
发布于 2016-07-10 13:36:18
似乎是通过使用命令来解决问题
git filter-branch --subdirectory-filter android_is_dir -- --all谢谢你@xnakos的耐心。此外,在此期间,我重新命名了分支,使用特殊的键(googled )和我单独推动的每一个新分支,它现在看起来棒极了,dev团队明天会很高兴)
顺便说一句,直到凌晨3点我才写了剧本,通过它我看到了每一个分支的全部历史,通过我没有看到分支之间的关系(合并)。
也许有人会发现它很有趣,脚本充满了拐杖和硬代码,但不管怎样,它对我很有用)
#!/usr/bin/python
import os
import json
import shutil
import subprocess
from distutils.dir_util import copy_tree
old_repo = "/home/ostetsia/coding/java"
old_repo_dir = "/home/ostetsia/coding/java/java_subdir"
new_repo = "/home/ostetsia/coding/java
old_repo_branch = "java/java_case_number"
new_repo_branch = "java_case_number"
#changing branch in new repo
os.chdir(new_repo)
try:
subprocess.check_output(["git", "branch", new_repo_branch])
except:
print "branch {0} exist in new repo".format(new_repo_branch)
subprocess.check_output(["git", "checkout", new_repo_branch])
os.chdir(old_repo)
try:
subprocess.check_output(["git", "branch", old_repo_branch])
except:
print "branch {0} exist in old repo".format(old_repo_branch)
os.chdir(old_repo)
subprocess.check_output(["git", "checkout", old_repo_branch])
git_add = "git add *"
git_old_log = subprocess.check_output(['git', 'log', '--reverse', '--pretty=format:{"hash": "%H", "reporter":"%an", "mail": "%ce", "date": "%cd", "comment": "%s"}'])
commit_list = {}
i=0
for data_line in git_old_log.split('\n'):
i+=1
data_line = json.loads(data_line)
commit_list[i] = dict(data_line)
git_old_log_count_commint = i
for commit, data in commit_list.iteritems():
for key, value in data.iteritems():
if key == "date":
date=value
print date
elif key == "mail":
mail = value
elif key == "hash":
hash = value
elif key == "comment":
comment = value
elif key == "reporter":
reporter = value
git_commit_command = "git commit -a --author='{0} <{1}>' --date='{2}' -am '{3}'".format(reporter, mail, date, comment)
#print git_commit_command
os.chdir(new_repo)
os.system("pwd")
os.system("rm -rf")
print commit
os.chdir(old_repo)
subprocess.check_output(["git", "checkout", hash])
copy_tree(old_repo_dir, new_repo)
os.chdir(new_repo)
os.system(git_add)
os.system(git_commit_command)
print os.getcwd()https://stackoverflow.com/questions/38282036
复制相似问题