【常用软件】Git 快捷笔记

创建本地仓库

git init

配置本地仓库的信息

git config --local user.name ""
git config --local user.email ""

查看本地仓库的配置信息

git config -l

跟踪文件的更新

git add <file> ...			# 指定文件
git add .					# 全部文件

取消对文件更新的跟踪

git restore --unstage <file> ...	# 指定文件
git reset HEAD <file> ...			# 指定文件
git reset							# 全部文件

查看跟踪状态

git status

放弃对文件的更改

git restore <file> ...		# 指定文件
git stash					# 全部文件

在本地仓库提交更新

git commit -m ""

撤销前N个提交

git reset --soft HEAD~N
##########
--soft		# 撤销提交, 不取消跟踪, 不会滚更改
--mixed		# 撤销提交, 取消跟踪, 不会滚更改
--hard		# 撤销提交, 取消跟踪, 回滚更改

更改commit信息

git commit --amend	# 进入vim编辑器更改更新日志

查看更新日志

git log

查看分支

git branch -a

创建分支

git branch <new_branch_name>

创建新分支并切换到新分支

git checkout -b <new_branch_name>

切换分支

git checkout <branch_name>
git checkout -			# 返回上一个分支

删除分支

git branch -d <branch_name>

在本地添加远程仓库链接

git remote add <remote_name> <remote_link>

在本地仓库删除远程仓库链接

git remote rm <remote_name>

在本地更改远程仓库的别名

git remote rename <old_name> <new_name>

向远程仓库推送更新

git push -u <remote_name> <local_branch>:<remote_branch>
git push -u <remote_name> <branch>		# 当本地分支与远程分支名字相同时
# -f 强制推送

从远程仓库拉取更新到本地

git pull <remote_name> <remote_branch>:<local_branch>
git pull <remote_name> <branch>			# 当本地分支与远程分支名字相同时

本地分支与远程分支之间存在差异,合并本地分支和远程分支

git fetch origin <remote_branch>:temp	# 下载远程分支到本地临时分支temp
git diff master temp					# 对比两个分支之间的差异
# 手动检查两个分支之间的差异, 决定取舍
git merge --no-commit temp				# 合并temp分支到当前分支, 不执行自动提交
# 此时可能出现 AutoMatic merge failed;fix conflicts and then commit the result
# 按照提示, 找到出现冲突的文件, 手动修改即可
git commit -m "<update message>"		# 提交更新
git push -u <remote_name> <branch>		# 更新远程仓库
git branch -d temp						# 将之前创建的临时分支删除

git merge 命令

详解git pull和git fetch的区别

AutoMatic merge failed;fix conflicts and then commit the result

未完待续…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值