Git 应用实例

实例一、合并本地和远程仓库的代码

应用场景

本地电脑上有远程仓库的代码并已做过修改,由于远程仓库的代码更新了,需要将本地和远程仓库的代码进行合并更新。即保留本地代码现有的修改且和远程仓库同步。

操作步骤

1
2
3
4
5
git init
git add -A
git commit -m <msg>
git pull <repository> --allow-unrelated-histories
git status

git pull 过程中会产生 CONFLICT (add/add): Merge conflict in <file> Automatic merge failed; fix conflicts and then commit the result. 冲突,需要手动解决冲突后再提交。解决冲突可参考 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 的“分支管理”->“解决冲突”。

1
2
git add -A
git commit -m <msg>
Powered By Valine
v1.4.16