Git-克隆与合并
克隆与合并
克隆
git clone first-steps first-steps-clone

对first-steps进行了克隆,该克隆库包含了first-steps的整个项目库和历史信息

原版本库修改
对first-steps/foo.txt进行修改,并提交
cd first-steps
vim foo.txt
git add foo.txt
git commit --message "A change in the original"


可以查看日志

克隆库修改
对first-steps-clone/bar.html进行修改,并提交
cd first-steps-clone
vim bar.html
git add bar.html
git commit --message "A change in the clone"

查看日志

合并
现在两个库都提交过修改,可以用pull(拉回)命令将两个库进行合并
git pull

通过图形化的日志可以看到合并的过程
git log --graph

可以看到commit:b6e3c与commit:6c17e合并为commit:1420f
从任意版本库pull(拉回)
回到first-steps版本库
cd first-steps
git pull ../first-steps-clone main

共享版本库
pull命令可以拉取其他版本库
push命令可以将提交上载到其他版本库,但是只适用于那些不带工作区的裸版本库
创建裸版本库,作为共享版本库
git clone --bare first-steps first-steps-bare.git

对first-steps/foo.txt进行修改,然后提交
cd first-steps
vim foo.txt
git add foo.txt
git commit --message "More changes in the original."

现在可以把first-steps上载到共享版本库first-steps-bare.git
git push ../first-steps-bare.git main

使用pull对克隆库进行相应的修改
cd first-steps-clone
git pull ../first-steps-bare.git main

版本库,克隆版本库,共享版本库之间的关系
如果,有人在你之前将版本库push到共享版本库,你需要先pull下来


浙公网安备 33010602011771号