git相关命令

1、git暂存区

		通过git stash存入暂存区
		git stash pop恢复之前暂存的改动

git stash 单个文件

git stash push js/common.js

git stash 多个文件

git stash push js/index.js js/second.js js/***.js

git stash 部分文件

git stash -p

但是如果直接git stash的话,会将当前所有文件都存储起来,而我只想存储两个配置文件,其他的全部一起commit,应该怎么办呢?这里需要用到一个git stash -p的命令;它是一个交互式命令,我们可以一个文件一个文件的遍历,决定每个文件的操作方式.

这里的[y,n,q,a,d,/,?]分别代表的含义如下:

   y - stage this hunk
   n - do not stage this hunk
   q - quit; do not stage this hunk nor any of the remaining ones
   a - stage this hunk and all later hunks in the file
   d - do not stage this hunk nor any of the later hunks in the file
   g - select a hunk to go to
   / - search for a hunk matching the given regex
   j - leave this hunk undecided, see next undecided hunk
   J - leave this hunk undecided, see next hunk
   k - leave this hunk undecided, see previous undecided hunk
   K - leave this hunk undecided, see previous hunk
   s - split the current hunk into smaller hunks
   e - manually edit the current hunk
   ? - print help

所以,遇到我们需要stash的文件,我们就y,不需要stash需要commit的文件,我们就n,如果接下来没有需要stash的文件,则直接q退出就行.

2、刷新git分支

	 git remote update origin --prune

3、查看git分支

	git branch -a

4、git撤销提交但是未push的代码

	git reset --soft HEAD^

5、git忽略文件夹

	在. .gitignore文件中添加     web/WEB/NTS.WEB.WebSite/log/
	就会忽略log文件夹下的文件

	*.a       # 忽略所有 .a 结尾的文件

6、[rejected] xxx xxxx (would clobber existing tag)

	原因:线上修改了 Tags(分支) ,再使用 VSCode 里的 pull 拉取分支时报错
	
	查看本地tag(分支)
	git tag -l
	删除 本地tag(分支)
	git tag -d xxx

7、合并分支

1、提交dev的修改
2、切换到master分支(git checkout master)
3、git merge dev (合并dev分支)
4、git push origin master (提交当前的更改到master分支)

git配置username、email

设置用户名和邮箱
git config --global user.name "username"
git config --global user.email  useremail@qq.com

8、git回退一个版本

git reset --hard HEAD^
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值