上周,我创建了一个Github回购协议,但忘了为回购协议 Select 许可证.现在已经有3个大型提交.
我问过三位贡献者,如果我删除回购协议,然后用相同的名称再次创建它,这一次在创建回购协议时 Select 许可证,是否可以,他们对此没有意见.
Question
有没有一种方法可以让提交进入新的repo(这次第一次提交是许可证文件)并且仍然保留提交元数据信息?
上周,我创建了一个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.对于那些没有的用户,他们可以克隆存储库的新副本.
以下是如何将许可证提交为第一次提交.
判断您的项目,并将许可证文件放在当前3提交堆栈上的提交中.
#create LICENSE file, edit, add content, save
git add LICENSE
git commit -m 'Initial commit'
然后在主分支上执行交互式重基,以完成REARRANGE次提交.
git rebase -i --root
它将打开一个编辑器.将底线(您的"初始提交"提交、最近的提交)移动到文件顶部.然后保存并退出编辑器.
一旦退出编辑器,git就会按照刚才指定的顺序编写提交.
现在,您已经更新了存储库的本地副本.做:
git log
核实一下.
既然你的副本已经更新了,你必须强制将其推送到github.
git push -f origin master
这将告诉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
就这样.现在每个人都应该同步.