Is there a way I have get the commits into new repo (this time the first commit is the LICENSE file) and still keep the commit meta info?
是的,通过在第一次提交的基础上添加远程和挑选提交。
# 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
这个答案的其余部分是你还想把LICENSE添加到你以前的回购中。
是。您可以通过rebase将LICENSE提交作为第一个提交。
重新引用是重新排列提交顺序的方法,同时保持所有提交作者和提交日期不变。
在处理共享仓库时,除非你的整个团队都是流利的,否则通常会气馁。对于那些不是,他们可以只是克隆存储库的新副本。
以下是您将LICENSE提交作为第一次提交的方式。
1.更新并修改本地副本
检查您的项目并将LICENSE文件放在当前3个提交堆栈的提交ON TOP中。
#create LICENSE file, edit, add content, save
git add LICENSE
git commit -m 'Initial commit'
然后在主分支上执行交互式rebase以重新提交提交。
git rebase -i --root
它会打开一个编辑器。将底线(您的“初始提交”提交,最近的提交)移动到文件的顶部。然后保存并退出编辑器。
退出编辑器后,git将按您刚刚指定的顺序编写提交。
您现在已更新存储库的本地副本。做:
git log
核实。
2.强制将新的repo状态推送到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
而已。现在每个人都应该同步。