git常用命令

常用命令

1.从远程仓库克隆项目到本地
git clone <项目地址 > 		# https/ssh 地址皆可以
2.初始化本地仓库.
git init 			# 创建本地仓库
3.本地仓库与远程仓库关联.
git remote add <仓库名> <仓库地址>	#  仓库名自定义 例如:origin
4.查看仓库名.
git remote  		# 查看远程仓库的仓库名,加-v 查看仓库名和地址
5.更换远程仓库地址.
git remote set-url <仓库名> <仓库地址>   # 
6.将文件添加添加到暂存区.
git add .	# . 代表所有,可以指定为具体文件 
7.将暂存区中的文件提交到本地仓库.
git commit -m “<备注说明>”		#
8.查看所有分支.
git branch		# 查看本地分支,加-a查看本地分支和远程分支,结果列表中前面标*标识当前使用分支.
9.创建分支.
git branch <分支名称 >		#
10.切换分支.
git checkout <分支名称>	#
11.将本地仓库的文件推动到远程仓库.
git push <仓库名> <分支名称>	# 推送时建议先(pull)更新一下
12.将远程仓库中跟新到本地.
git pull <仓库名>  <分支名称>	#
13.修改远程仓库名称.
git remote rename <旧名称>  <新名称>	#
14.查看提交记录
git log   #
15.回滚提交
#Reset会把后面提交的记录直接删掉
git reset --hard [commit hash]		# 例如:git reset --hard 7b8bcaa0b02959126b923fe554824fa9df1dfd87
16.分支合并到主分支上
git merge <分支名称>
17.windows 禁止自动将 lf 转换成 crlf
git config --global core.autocrlf false
# 查看结果命令
git config --global -l
#查询结果
core.autocrlf=false

常见错误

1.提交缓存区中内容到本地仓库
1.1.报错信息如下:
D:\xx\xx>git commit -m"初始化"

*** Please tell me who you are.

Run

 	git config --global user.email "you@example.com"
    git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'admin@DESKTOP-NHBTH4U.(none)')
1.2.报错原因:
出现错误的原因是因为无用户信息
1.3.解决方案:
# 1.添加你的邮箱
git config --global user.email "xxxx@qq.com"
# 2 添加你的昵称
git config --global user.name "name"
2.本地仓库提交至远程仓库时
2.1.报错信息如下:
D:\xxx\xxx>git push origin master
To https://gitee.com/xxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/xxx/xxx.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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
2.2.报错原因:
	出现错误的主要原因是gitee中的README.md文件不在本地代码目录中
2.3.解决方案:
# 1.合并代码
git pull --rebase origin master
# 2.再次提交
git push origin master
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值