git 提示无法 pull 仓库(refusing-to-merge-unrelated-histories)

背景 在本地完成了一个项目,并使用 git 完成了初始化。 然后想同步到 github 上去,便在 github 上 new repository 创建了一个新的库,并勾选了 Initialize this repository with a README,也就是这个仓库初始化的时候将自动带有一个 Readme.md 文件。 在 github 上创建好 repo 后,接下来的操作自然是将本地仓库 push 到远程仓库上。 因为 github 上的 repo 带有 Readme.md,而本地的没有,所以就需要先将 github 上的 pull 下来。 在执行 git pull 命令后,便出现了一条合并失败的提示。 fatal: refusing to merge unrelated histories 提示的意思是,拒绝合并不相关的历史。 解决 Google 了一下后得知,两个仓库(本地和远程)都有 commit,但是却没有相关联的 commit,因此 git 认为用户应该是填错了 origin,两个仓库并无关联。 这个时候只要给命令加个选项便可以解决问题了(–allow-unrelated-histories)。 git pull origin master --allow-unrelated-historie

November 12, 2018 · 1 min · vdorchan

从 svn 迁移到 git,并保留 commit 日志

之前为公司做了个基于 yeoman 的脚手架工具,公司是使用 svn 做版本控制的,所以这个工具也就使用了 svn 来记录版本。 近期想做个迁移,把它放到 github 上去,这里对迁移过程做个简单的记录。 首先,svn 地址是 http://svn.com.cn/svn/generator-pczt/ (非真实 svn 地址,这里做个举例) 该项目位置在 svn 中的 base repository,因此不涉及到 tags,branches,trunk。 用户映射 按照网上文章,先创建个文件(users.txt),做个用户映射,将 svn 的用户和 git 上的用户关联起来。 chenwudong = vdorchan <vdorchan@gmail.com> git svn clone 按照文档中的命令 # --stdlayout 跟踪标准的Subversion存储库 # -authors-file 指定用户映射的文件 git svn clone --stdlayout --no-metadata -authors-file=users.txt http://svn.com.cn/svn/generator-pczt/ generator-pczt 输入上述的命令后,在 generator-pczt中创建了一个空的 git 仓库,但并没有将文件从 svn 拉下来,并且命令行输出了以下的一些信息。 Initialized empty Git repository in /Users/vdorchan/Documents/www/Learn-Yeoman/generator-pczt/.git/ Using higher level of URL: http://svn.com.cn/svn/generator-pczt => http://svn.com.cn/svn W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 100, path '/generator-pczt' W: Do not be alarmed at the above message git-svn is just searching aggressively for old history....

November 9, 2018 · 1 min · vdorchan