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^