linxu下命令解析(git)
2013-09-04 17:16
148 查看
一、本地建立仓库
先创建个文件夹,仓库的地点: mkdir cangkumkdir CloudNAT
cd CloudNAT
初始化git仓库:git init
把项目代码,文档等文件放到当前目录下: cp src/*.* ./CloudNAT/
将文件送入git仓库: git add .
此时可以查看一下git仓库当前的状态,用于确认信息:git status 输出类似如下的信息,提示有变化,新增了文件,尚未commit 等等:
linux # git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: CloudNAT/.classpath # new file: CloudNAT/.project
确认正确没问题,就可以提交了: git commit -m "thomasnew add for CloudNAT" // -m 参数添加本次提交的注释信息。
linux # git commit [master (root-commit) 8c10939] thomasnew add for CloudNAT 124 files changed, 6732 insertions(+), 0 deletions(-) create mode 100644 CloudNAT/.classpath create mode 100644 CloudNAT/.project
如果本地的代码需要和远程的仓库进行同步,只需要添加一个remote链接即可
首先设置自己的用户名和邮箱信息,这样向远程仓库提交代码时,可以留下作者信息。做好事和坏事都要留名阿。
git config --global user.name "thomasnew" git config --global user.email "thomasnew@company.com"
# git config --list user.name=thomasnew user.email=thomasnew@company.com
# 生成ssh公共密钥,加到remote server上
# ssh-keygen -t rsa -c "thomasnew@company.com" //生成pub key文件
# ssh-agent bash //设置agent
# ssh-add <id-rsa-file> //把刚生成的文件add上
然后就可以添加remote链接了:
git remote add CloudNAT ssh://thomasnew@192.168.11.11:29999/projects/CloudNAT
可以添加多个链接,对应不同的远程仓库,当然要用不同的名字加以区分
linux # git remote -v CloudNAT ssh://thomasnew@192.168.11.11:29999/projects/CloudNAT (fetch) CloudNAT ssh://thomasnew@192.168.11.11:29999/projects/CloudNAT (push)
以后修改了代码,并完成测试确认无误后,就可以推送到远程的仓库中去,这样别人就可以共享你的成果了:
git push CloudNAT master
别人提交到远程仓库的代码,可以通过clone命令取到本地,clone用于第一次获取,把取来的文件放在一个新的目录下;
git clone ssh://thomasnew@192.168.11.11:29999/projects/CloudNAT ./CloudNAT
如果是获取增量更新的代码,用pull;
cd CloudNAT
git pull origin
git pull origin CloudNAT //同步远程主线的修改,合并到本地。
相关文章推荐
- git分支原理命令图文解析
- Git 之 reset 命令解析
- git plumbing 更加底层命令解析-深入理解GIT
- 关于Git的merge和rebase命令解析
- Git 命令场景解析
- git log命令全解析
- Git命令解析
- Git 从入门到精通(常用命令解析)(一)
- git最常用!最实用!最基本的命令解析!绝对够用!
- git 常用命令解析
- git 和 phabricator arc 常用 命令解析
- Git 常用命令 解析
- 【git】常用命令之解析
- Git命令解析
- GIT使用命令全解析
- git常用的命令解析
- git 常见命令解析
- git初学常用命令解析
- git 常用命令及解析 由浅入深
- git 和 phabricator arc 常用 命令解析