Linux 如何将提交从一个Git回购复制到另一个Git回购?
上周我创建了一个Github回购协议,但忘记了为回购协议选择许可证。现在已经有3个大型提交Linux 如何将提交从一个Git回购复制到另一个Git回购?,linux,git,github,Linux,Git,Github,上周我创建了一个Github回购协议,但忘记了为回购协议选择许可证。现在已经有3个大型提交 git rebase -i --root 我问过3个参与者是否可以,如果我删除了回购协议,然后用相同的名称再次创建,这次在创建回购协议时选择了许可证,他们会怎么做 问题 有没有办法让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息 有没有办法让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息 是的,通过在第一次提交的基础上添加一个远程文件并选择提交
git rebase -i --root
我问过3个参与者是否可以,如果我删除了回购协议,然后用相同的名称再次创建,这次在创建回购协议时选择了许可证,他们会怎么做
问题
有没有办法让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息
有没有办法让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息
是的,通过在第一次提交的基础上添加一个远程文件并选择提交
# add the old repo as a remote repository
git remote add oldrepo https://github.com/path/to/oldrepo
# get the old repo commits
git remote update
# examine the whole tree
git log --all --oneline --graph --decorate
# copy (cherry-pick) the commits from the old repo into your new local one
git cherry-pick sha-of-commit-one
git cherry-pick sha-of-commit-two
git cherry-pick sha-of-commit-three
# check your local repo is correct
git log
# send your new tree (repo state) to github
git push origin master
# remove the now-unneeded reference to oldrepo
git remote remove oldrepo
这个答案的其余部分是,如果您仍然希望将许可证添加到以前的回购协议中 对。您可以通过重定基址将许可证提交作为第一次提交 重定基址是gits重新安排提交顺序的一种方式,同时保持所有提交作者和提交日期不变 在处理共享回购协议时,通常不鼓励这样做,除非您的整个团队都精通git。对于那些没有的用户,他们只需克隆存储库的一个新副本 以下是如何将许可证提交为第一次提交
# add the old repo as a remote repository
git remote add oldrepo https://github.com/path/to/oldrepo
# get the old repo commits
git remote update
# examine the whole tree
git log --all --oneline --graph --decorate
# copy (cherry-pick) the commits from the old repo into your new local one
git cherry-pick sha-of-commit-one
git cherry-pick sha-of-commit-two
git cherry-pick sha-of-commit-three
# check your local repo is correct
git log
# send your new tree (repo state) to github
git push origin master
# remove the now-unneeded reference to oldrepo
git remote remove oldrepo
1.更新本地副本并重新设置其基础
签出您的项目并将许可证文件放在当前3提交堆栈顶部的提交中
#create LICENSE file, edit, add content, save
git add LICENSE
git commit -m 'Initial commit'
然后在主分支上执行交互式重基以重新排列提交
git rebase -i --root
它将打开一个编辑器。将底线(您的“初始提交”提交、最近的提交)移动到文件顶部。然后保存并退出编辑器
一旦退出编辑器,git将按照刚才指定的顺序写入提交
现在,您已经更新了存储库的本地副本。做:
git log
核实
2.强制将您的新回购状态推送到github
现在您的副本已经更新,您必须强制将其推送到github
git push -f origin master
这将告诉github将主分支移动到其新位置。
您应该只在很少的情况下强制推送,因为与它一起工作的每个人都知道挂起的更改,否则会混淆您的合作者
3.将协作者同步到github
最后,所有协作者都必须同步到此存储库
首先,它们必须具有干净的存储库,因为如果存在未保存的更改,则以下命令可能具有破坏性
# make sure there are no unsaved changes
git status
# pull the latest version from github
git fetch
# move their master branch pointer to the one you published to github.
git reset --hard origin/master
就这样。现在每个人都应该同步了。我遇到了一个类似的问题,在我意识到我的错误之前,我忘记了向我的github进行回购,并添加了几个提交 我找到了一个非常简单的解决方案 首先,将遥控器移到原始回购
git远程删除源站
其次,在我的github上的新fork中添加一个remote
git远程添加源站
然后我推到了origin master,我所有的提交都显示在我的github上。- 目标Git=UrlD(现有内容无关紧要)
- SourceGit=url
git clone UrlS git remote add origin2 UrlD git push -f origin2 master
现在,目标将具有与源相同的数据(您也可以使用origin而不是origin2)我使用了以下方法:
- 将源repo克隆到/c/SrcRepo这样的文件夹中
- 将目标repo克隆到/c/DstRepo这样的文件夹,并切换到目标分支
- 在目标repo的根文件夹中运行以下命令: git pull/c/SrcRepo srcBranch——允许不相关的历史记录
无需根据@Moocowmoo的答案创建额外的远程参考,但尝试将其简化一点 不同的是,只要假设遥控器是正确的,就尽量避免冲突 但是,它不能很好地处理删除的文件,因此仍然有一个手动元素
#假设您已经在您想要的分支上
git远程添加oldrepohttps://github.com/path/to/oldrepo
git旧回购
#从分支中获取所有更改或更改的子集
git cherry pick--策略递归--策略选项他们最早的委员会^..最晚的委员会
#或接受特定合并提交中包含的所有更改(最简单)
git cherry pick--策略递归--策略选项mergeCommitHash^..mergeCommitHash
#处理已删除的文件/未处理的冲突
#继续重复这一节
git合并工具
#c/m或d取决于您是否要保留或删除文件
git cherry pick--继续
就我而言,我需要找出新旧回购协议之间的差异。因此,在新回购协议中增加了旧回购协议
git remote add old https://gitlab.site.az/old-blog.git
取回所有遥控器
git fetch --all
查找不同的提交
git log --graph --oneline --pretty=format:"%h%x09%an%x09%ad%x09%s" --abbrev-commit --date=relative develop..old/develop
获取您选择的提交
git cherry-pick SHA1 SHA2 SHA4
您仍然可以向原始回购协议添加许可证。有关详细信息,请参阅。相关的可能重复:
git checerry pick commit1..commit2
!谢谢节省了很多时间。谢谢更重要的是,当我推的时候,我不得不做git推--set-upstream-origin-master
,但是git让你意识到了这一点。伟大而简单的解决方案!