git使用

git是linux下的分布式版本管理工具,由linus开发。 

1.查看帮助
  git help command
2.显示带修改记录的log信息
  git log --stat

3.修改刚提交的注释
  git commit --amend
4.获取文件的历史版本

  git checkout [commit] [file]

5.版本回滚

  git reset --hard [commit]

  可以向前,也可以重设到当前

6.Basic example: merge repo B into repo A

Let’s keep calling the repos A and B for the moment, assume we are merging B into A, and consider the following simple example first. We’ll create a remote inside A pointing to B, then merge B’s master branch into A’s master branch.

Clone both repositories into the same directory and go into repo A:

$ git clone A

$ git clone B

$ cd A

Add a remote called B that points to the repo B (do git remote -v to view your remotes), and fetch copies of all B’s branches:

$ git remote add B ../B

$ git fetch B

To view all B’s branches that we’ve just fetched, do git branch -a. You should see B/master in the list. Now, still in repo A, create a branch called B-master in repo A that tracks B/master.

$ git branch B-master B/master

If you’re not already in the master branch, check it out, then merge B-master into A’s master.

$ git merge B-master

Assuming you have no merge conflicts, you’re done!

7.copy remote non master branch

git clone /home/dhliu/repository --branch tray_v2

8.建立git服务器
参照http://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%9C%A8%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E6%90%AD%E5%BB%BA-Git
下面只介绍我经常使用的操作
8.1将现有仓库导出为裸仓库
$ git clone --bare my_project my_project.git
8.2把裸仓库放到远程服务器上
$ scp -r my_project.git user@git.example.com:/opt/git
8.3把裸仓库copy到本地
$ git clone user@git.example.com:/opt/git
$ git clone user@git.example.com:/opt/git --branch branch_2
8.4提交本地仓库
$ git commit -a
8.5上传本地到服务器
$ git push user@git.example.com:/opt/git
$ git push user@git.example.com:/opt/git branch_2
8.6同步本地仓库
$ git pull user@git.example.com:/opt/git
$ git pull user@git.example.com:/opt/git branch_2

9.推送冲突处理
git push出错处理;原因 本地仓库与远程服务器代码不一致,缺少服务器已有的提交。
处理步骤:
1)git pull 拉取远程最新修改;
2)git diff 查看修改项
类似
++<<<<<<< HEAD    本地内容
 +3rd modify by A
++=======              远程内容开始
+ third modify by B
++>>>>>>> d0cca4d4a6b8b17ebfa7a9016bbbd4dea60e4b77远程内容结束
3) 使用任意编辑器手工合并冲突内容
4)git commit -a
5) git push

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值