上周,我创建了一个Github回购协议,但忘了为回购协议 Select 许可证.现在已经有3个大型提交.

我问过三位贡献者,如果我删除回购协议,然后用相同的名称再次创建它,这一次在创建回购协议时 Select 许可证,是否可以,他们对此没有意见.

Question

有没有一种方法可以让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息?

推荐答案

有没有一种方法可以让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息?

是的,通过在第一次提交的基础上添加一个远程文件并 Select 提交.

# 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.对于那些没有的用户,他们可以克隆存储库的新副本.

以下是如何将许可证提交为第一次提交.

1. Update and rebase your local copy

判断您的项目,并将许可证文件放在当前3提交堆栈上的提交中.

#create LICENSE file, edit, add content, save
git add LICENSE
git commit -m 'Initial commit'

然后在主分支上执行交互式重基,以完成REARRANGE次提交.

git rebase -i --root

它将打开一个编辑器.将底线(您的"初始提交"提交、最近的提交)移动到文件顶部.然后保存并退出编辑器.

一旦退出编辑器,git就会按照刚才指定的顺序编写提交.

现在,您已经更新了存储库的本地副本.做:

git log

核实一下.

2. Force push your new repo state to github

既然你的副本已经更新了,你必须强制将其推送到github.

git push -f origin master

这将告诉github将主分支移动到新位置.

3. Synchronize collaborators to github

最后,所有协作者都必须同步到此存储库.

如果有未保存的更改,则以下命令可能具有 destruct 性.

# 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

就这样.现在每个人都应该同步.

Linux相关问答推荐

bind() 错误 98 - 地址已在使用中

linux shell 脚本获取文件夹中

使用 awk 将多行文本转换为 CSV

使用 bash 中的数字对 RPM 内核字符串进行版本排序返回不正确的结果

查找在特定日期从特定机器登录的所有用户

在 Bash 中从最后到第一个输出文件行

Linux 应用程序分析

任何方式以编程方式在android上运行shell命令?

通过 VM 的 Centos - 镜像列表中没有 URL

如何在 Bash 中对齐空格分隔表的列?

Pthread mutex互斥断言错误

如何运行我所有的 PHPUnit 测试?

如何从 Linux 终端找到特定文件?

Android - 找不到命令

如何使用mv命令移动特定目录中的文件除外?

查找和基本名称不能很好地播放

为嵌入式 Linux 设备实施更新/升级系统

在 Docker 容器中运行的 JVM 的驻留集大小 (RSS) 和 Java 总提交内存 (NMT) 之间的差异

内联 if shell 脚本

Linux 上 POSIX AIO 和 libaio 的区别?