有没有一种方法可以将提交提交到新的存储库中(这次第一次提交是LICENSE文件),并且仍然保留提交元信息?
是的,通过在第一次提交的基础上添加一个远程并精心挑选的提交。
# add the old repo as a remote repository git remote add oldrepo https://github.com/path/to/oldrepo# get the old repo commitsgit remote update# examine the whole treegit log --all --oneline --graph --decorate# copy (cherry-pick) the commits from the old repo into your new local onegit cherry-pick sha-of-commit-onegit cherry-pick sha-of-commit-twogit cherry-pick sha-of-commit-three# check your local repo is correctgit log# send your new tree (repo state) to githubgit push origin master# remove the now-unneeded reference to oldrepogit remote remove oldrepo
该答案的其余部分是,如果您仍想将LICENSE添加到以前的仓库中。
是。您可以通过重新定级将LICENSE提交作为第一个提交。
变基是重新排列提交顺序,同时保持所有提交作者和提交日期不变的gits方法。
在共享仓库上工作时,除非您的整个团队精通流水,否则通常不建议这样做。对于那些不是的人,他们可以克隆存储库的新副本。
这是您第一次获得LICENSE提交的方式。
1.更新您的本地副本并使其变基
签出您的项目,并将LICENSE文件放入当前3个提交堆栈的ON TOP提交中。
#create LICENSE file, edit, add content, savegit add LICENSEgit commit -m 'Initial commit'
然后在master分支上进行交互式变基,以 重新 确定提交。
git rebase -i --root
它将打开一个编辑器。将底行(您的“初始提交”提交,最近的提交)移动到文件的顶部。然后保存并退出编辑器。
退出编辑器后,git将按照您刚才指定的顺序写入提交。
现在,您已更新了存储库的本地副本。做:
git log
核实。
2.强制将新的回购状态推送到github
现在,您的副本已更新,您必须强制将其推送到github。
git push -f origin master
这将告诉github将master分支移动到新位置。您仅应在这种罕见的情况下强制推送,每个人都在与它一起工作时意识到即将发生的更改,否则它将使您的协作者感到困惑。
3.将协作者同步到github
最后,所有协作者都必须同步到该存储库。
首先, 它们必须具有干净的存储库, 因为如果有未保存的更改,则以下命令可能具有破坏性。
# make sure there are no unsaved changesgit status# pull the latest version from githubgit fetch# move their master branch pointer to the one you published to github.git reset --hard origin/master
而已。现在每个人都应该保持同步。



