Git 版本控制器使用指南-II(远程代码控制)
2017-03-23 13:55
639 查看
这篇主要讲的是FreeBSD上部署的Git中,远程的代码仓储的使用,下面是Git远程的测试,服务器和客户机还是同一台虚拟机,使用另外创建的git用户测试!
1.git clone 可以远程克隆一个库,并且系统默认其为origin库
这里将服务器的代码同步下来了,同步的时候需要输入密码。
这里需要注意的是,我们的hello.exe被写入.gitignore忽略跟踪了,所以git同步下来的代码中没有这个文件,还有就是这个clone是使用ssh远程克隆的,所以权限可以的话,就可以提交代码到远程仓库上去,
因为ssh是一个可以读写的协议 ;而如果使用http或者git协议,直接 git clone git://— ,就是一个只读的拷贝,无法提交代码的
2.显示远程仓库的信息
3.跟新同步到远程仓库分支
我们在远程仓库进行了更改,添加了test.txt文件,然后这里 git fetch origin 可以查看到,远程的库已经发生了改变
原来的修改并没有被更新下来,使用merge将远程的修改和本地的原始版本进行合并,就实现了代码的实质更新了 git merge (远程仓储名)/(分支名称)
实际上pull就是 fetch 和 merge的组合,所以上面可以简化成 git pull (远程仓储名) (分支名称)
4.提交本地修改到远程存储仓库
而如果想把本地的更改更新到远程的服务器上面,可以使用 git push (远程仓储名) (分支名称)
上面的错误是因为文件系统的权限问题,我们 给git用户以wheel组的身份 ,同时代码树的组写权限也打开
然后就可以push代码更新了
为了测试代码提交的结果,最后我们新建一个目录,重新从服务器上面下载代码,就可以看到新的结果体现出来了
[git@zfsworkstation ~/gitwork]$ git config --global user.name "Git.TAO" [git@zfsworkstation ~/gitwork]$ git config --global user.email "taoscu@gmail.com" [git@zfsworkstation ~/gitwork]$ git config --list core.editor=emacs user.name=Git.TAO user.email=taoscu@gmail.com
1.git clone 可以远程克隆一个库,并且系统默认其为origin库
[git@zfsworkstation ~/gitwork]$ ls -al /home/taozj/source_code/git/repo/helloworld/ .git/ .gitignore Makefile README.txt hello.cpp hello.exe [git@zfsworkstation ~/gitwork]$ ls /home/taozj/source_code/git/repo/helloworld/ Makefile README.txt hello.cpp hello.exe [git@zfsworkstation ~/gitwork]$ git clone ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld Cloning into helloworld... Password: remote: Counting objects: 28, done. remote: Compressing objects: 100% (22/22), done. remote: Total 28 (delta 7), reused 0 (delta 0) Receiving objects: 100% (28/28), done. Resolving deltas: 100% (7/7), done. [git@zfsworkstation ~/gitwork]$ ls helloworld/ Makefile README.txt hello.cpp [git@zfsworkstation ~/gitwork]$ ls -a helloworld/ . .. .git .gitignore Makefile README.txt hello.cpp
这里将服务器的代码同步下来了,同步的时候需要输入密码。
这里需要注意的是,我们的hello.exe被写入.gitignore忽略跟踪了,所以git同步下来的代码中没有这个文件,还有就是这个clone是使用ssh远程克隆的,所以权限可以的话,就可以提交代码到远程仓库上去,
因为ssh是一个可以读写的协议 ;而如果使用http或者git协议,直接 git clone git://— ,就是一个只读的拷贝,无法提交代码的
2.显示远程仓库的信息
[git@zfsworkstation ~/gitwork]$ cd helloworld/ [git@zfsworkstation ~/gitwork/helloworld]$ git remote -v origin ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld (fetch) origin ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld (push) [git@zfsworkstation ~/gitwork/helloworld]$ git remote show origin Password: * remote origin Fetch URL: ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld Push URL: ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)
3.跟新同步到远程仓库分支
我们在远程仓库进行了更改,添加了test.txt文件,然后这里 git fetch origin 可以查看到,远程的库已经发生了改变
[git@zfsworkstation ~/gitwork/helloworld]$ git fetch origin Password: remote: Counting objects: 4, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ssh://zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld 09dccf0..c55af4b master -> origin/master [git@zfsworkstation ~/gitwork/helloworld]$ git remote show origin Password: * remote origin Fetch URL: ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld Push URL: ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (local out of date)
原来的修改并没有被更新下来,使用merge将远程的修改和本地的原始版本进行合并,就实现了代码的实质更新了 git merge (远程仓储名)/(分支名称)
[git@zfsworkstation ~/gitwork/helloworld]$ git merge origin/master Updating 09dccf0..c55af4b Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.txt [git@zfsworkstation ~/gitwork/helloworld]$ ls Makefile README.txt hello.cpp test.txt
实际上pull就是 fetch 和 merge的组合,所以上面可以简化成 git pull (远程仓储名) (分支名称)
[git@zfsworkstation ~/gitwork/helloworld]$ git pull origin master Password: From ssh://zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld * branch master -> FETCH_HEAD Already up-to-date.
4.提交本地修改到远程存储仓库
而如果想把本地的更改更新到远程的服务器上面,可以使用 git push (远程仓储名) (分支名称)
[git@zfsworkstation ~/gitwork/helloworld]$ touch test2.txt [git@zfsworkstation ~/gitwork/helloworld]$ git push origin master [git@zfsworkstation ~/gitwork/helloworld]$ git add test2.txt [git@zfsworkstation ~/gitwork/helloworld]$ git commit -m "for test2.txt push test" [master 177fc0e] for test2.txt push test 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test2.txt [git@zfsworkstation ~/gitwork/helloworld]$ git push origin master Password: Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 245 bytes, done. Total 2 (delta 1), reused 0 (delta 0) error: insufficient permission for adding an object to repository database ./objects fatal: failed to write object error: unpack failed: unpack-objects abnormal exit To ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld ! [remote rejected] master -> master (n/a (unpacker error)) error: failed to push some refs to 'ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld'
上面的错误是因为文件系统的权限问题,我们 给git用户以wheel组的身份 ,同时代码树的组写权限也打开
[taozj@zfsworkstation ~/source_code/git]$ sudo pw usermod -n git -g wheel [taozj@zfsworkstation ~]$ chmod -R g+w source_code
然后就可以push代码更新了
[git@zfsworkstation ~/gitwork/helloworld]$ git push origin master Password: Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 216 bytes, done. Total 2 (delta 1), reused 0 (delta 0) To ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld ac1817f..2796f6c master -> master
为了测试代码提交的结果,最后我们新建一个目录,重新从服务器上面下载代码,就可以看到新的结果体现出来了
[git@zfsworkstation ~/gitwork/testdir2]$ git clone ssh://git@zfsworkstation.peachzone.org/home/taozj/source_code/git/repo/helloworld Cloning into helloworld... Password: remote: Counting objects: 37, done. remote: Compressing objects: 100% (29/29), done. remote: Total 37 (delta 11), reused 0 (delta 0) Receiving objects: 100% (37/37), done. Resolving deltas: 100% (11/11), done. [git@zfsworkstation ~/gitwork/testdir2]$ ls helloworld [git@zfsworkstation ~/gitwork/testdir2]$ cd helloworld/ [git@zfsworkstation ~/gitwork/testdir2/helloworld]$ ls Makefile README.txt hello.cpp test.txt test2.txt
相关文章推荐
- Windows下Qt Creator使用版本控制器Git来进行版本控制,GitHub进行代码托管
- 版本控制工具 git 使用入门指南
- Git使用手册/Git教程:git fetch 将远程仓库的分支及分支最新版本代码拉取到本地
- 版本控制(下)——使用Git将代码托管到github
- idea使用git进行代码的版本控制
- xcode 版本控制推送代码到远程git仓库的步骤
- 使用Git进行版本控制:(2)在OS X系统上开始使用Git代码仓储
- 使用git和github 进行代码的版本控制
- OS(关于版本控制)使用git 创建远程仓库-熟知这些命令行,带你装逼带你飞!
- git的注册与使用:代码的版本控制器
- 版本控制工具git使用指南
- Xcode中使用Git进行代码版本控制
- Hello China 最新版本V1.6源代码和使用指南,已发布到:http://download.csdn.net/source/1054702
- Android Studio-Git的使用(项目管理与版本控制)
- git在本地创建工作空间并从远程版本库获取代码
- 使用androidstudio自带的git插件进行版本控制图文详解
- Git版本控制器使用总结性梳理
- 在Xcode中使用Git进行源码版本控制
- 在Xcode中使用Git进行源码版本控制
- GIT使用—创建并使用远程版本库