Git常用命令

总结了一些在工作中频繁用到的Git命令,基本上可以满足需求;
Git其实很简单,能用即可。

1.比较提交 - Git Diff

$ git diff master..test
$ git diff master...test

2.克隆项目 - Git Clone

$ git clone http://git.shiyanlou.com/shiyanlou/gitproject
$ git clone /home/shiyanlou/gitproject myrepo

3.提交修改 - Git Add

$ git add newfile
$ git add -u

这个命令的意思是

add to index only files modified or deleted and not those created

只会处理已修改或者已删除的文件,但是不会处理新建的文件

$ git commit -m "add"

4.合并分支 - Git Pull

$ git pull /home/shiyanlou/myrepo master

5.查看修改 - Git Log

$ git log -p master..myrepo/master

6.全局配置 - Git Config

git config --global user.email "keleix@gmail.com"
git config --global user.name "Kallen"

7.完整使用流程

(1) git init

$ git init
$ git pull https://github.com/keleir/BlogProj.git

(2) git commit

$ git add *
$ git add LICENSE
$ git commit -m "Initial Commit"

(3) git remote

$ git remote
origin
$ git remote -v
origin  https://github.com/Keleir/BlogProj.git (fetch)
origin  https://github.com/Keleir/BlogProj.ssgit (push)
$ git remote add origin https://github.com/Keleir/BlogProj.git

(4) git push

$ git push
Username for 'https://github.com': Keleir
Password for 'https://Keleir@github.com': 
Counting objects: 15, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 1.50 KiB | 0 bytes/s, done.
Total 8 (delta 6), reused 0 (delta 0)
To https://github.com/Keleir/BlogProj.git
   47688f3..e22a55b  master -> master 

8.FAQ

(1) git push出错

failed to push some refs to 'https://github.com/Keleir/Arigue.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

【解决办法】

 git pull origin master
 git push -u origin master -f

热门推荐

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值