用libgit2实现’git pull’?
我有一个相对较短的Gist ,它应该使用libgit2
来模拟git pull
命令的function。 不幸的是,它并没有完全奏效。
总之,代码片段:
- 调用
git_repository_open()
来打开磁盘上的存储库 - 调用
git_remote_load()
来获取名为“origin”的远程git_remote *
- 使用
GIT_DIRECTION_FETCH
标志调用git_remote_connect()
- 调用
git_remote_download()
从远程获取对象
根据git_remote_stats()
,确实正在获取对象。 但工作目录不会更改以反映最新的提交。 我尝试添加:
git_checkout_head(repo, NULL);
……但这没有任何区别。
输入:
git checkout master
…在终端中产生以下输出:
已经'掌握'了 您的分支通过1次提交落后于“origin / master”,并且可以快速转发。
我如何快进?
你应该运行git pull origin master
要么
git fetch origin
+ git merge origin/master
那意味着你需要等效的libgit2合并function。
合并function在libgit2 v0.20中可用