git使用基础

转载请说明出处http://blog.csdn.net/aa635335061/article/details/79000503

一、基本环境搭建

1、安装cygwin

2、cygwin安装git

3、git config -l 查看配置情况

$ git config --local -l 
fatal: --local can only be used inside a git repository

$ git config --system -l 
fatal: unable to read config file '/etc/gitconfig': No such file or directory

$ git config --global -l 
fatal: unable to read config file '/home/63533/.gitconfig': No such file or directory

4、安装完后vi /home/../.gitconfig

 

[user]
name = AKUKe
email = 635335061@qq.com
[color]
diff = auto
status = auto
branch = auto
interactive = true
ui = true
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
type = cat-file -t
dump = cat-file -p
[core]
autocrlf = false

 

当然也可以使用git config -e进行配置,效果一样

二、git的基础使用

1、在当前目录初始化生成.git文件夹

git init

 

2、显示本地分支和远程分支

git br -a

 

3、切换分支

git co <branch>

4、新建devel本地分支并切换到devel分支

 

 

git co -b devel

 

5、显示工作区与最近一次提交的差异

git diff HEAD

 

6、添加所有文件到暂存区

 

git add .

7、提交到本地仓库并注释

 

 

git ci -m"message"

8、显示所处状态

git st

 

9、将本地仓库代码提交推到远程服务器

 

git push [<远程主机名> <本地分支名>:<远程分支名>]

10、查看提交历史记录

git hist

11、不清空暂存区重置不强制回滚工作区   || 清空暂存区重置强制回滚工作区   || 工作区所做修改回滚

git reset --soft <版本号>  || git reset --hard <版本号>  || git co <版本号>

 

12、查看提交版本并强制重置当前版本

git reflog [show <branch> [| HEAD -n 数量]]  => git reset --hard <branch>@{序号}

 

13、获取最新版本到本地,合并分支到当前分支

git pull [origin <branch>]   || git fetch [origin <branch>]  => git merge [origin <branch>]

14、更新冲突的文件

git add -u [.]

15、取消暂存区文件

git reset HEAD <文件>

 

附图一张

实战案例

1.回滚到历史版本代码

2.如何修改历史版本代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值