Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git 命令常用速查表 #181

Open
ly2011 opened this issue Aug 5, 2019 · 0 comments
Open

Git 命令常用速查表 #181

ly2011 opened this issue Aug 5, 2019 · 0 comments

Comments

@ly2011
Copy link
Owner

ly2011 commented Aug 5, 2019

Git 命令常用速查表

git配置规范

# 姓用户名
$ git config --global user.name "Your Name"
# 用户邮箱
$ git config --global user.email "email@example.com"
# 设置换行符均不转换
$ git config --global core.autocrlf false
# 设置大小写敏感
git config --global core.ignorecase false

删除分支/恢复分支

  1. 删除一个被终止的分支
    如果需要删除的分支不是当前正在打开的分支,使用branch -d直接删除
git branch -d <branch_name>
  1. 删除一个正在打开的分支

如果我们在试图删除一个分支时自己还没转移到另外的分支上(或者被删除的分支还有文件没被提交),Git就会给出一个警告,并拒绝改删除操作。
如果坚持删除改分支的话,就需要在命令中使用 -D 选项

git branch -D <branch_name>

撤销

commit之后,想撤销commit

git reset --soft HEAD^

注意,仅仅是撤回commit操作,你写的代码依然保留
HEAD^是上一个版本,也可以写成HEAD~1

git reset的几个参数如下:

  • --mixed

意思是:不删除工作空间改动代码,撤销commit,并且撤销git add .操作,这个为默认参数,git reset --mixed HEAD^git reset HEAD^ 效果是一样的。

  • --soft

不删除工作空间改动代码,撤销commit,不撤销git add .

  • --hard

删除工作空间改动代码,撤销commit,撤销git add .

注意:完成这个操作后,就恢复到了上一次的commit状态

暂存

git stash

# 查询所有暂存
git stash list

# 取出暂存
git stash pop

# 取出某个暂存(一定要加双引号)
git stash pop "stash@{0}"

# 删除某个暂存
git stash drop "stash@{0}"  这是删除第一个队列

远程操作

指定从某个远程分支(如dev)更新代码到当前分支

git pull origin dev

Git 清理无效的远程追踪分支

如果在远程版本库上删除了某一分支,该命令并不会删除本地的远程追踪分支

  1. 使用如下命令查看哪些分支需要清理
git remote prune origin --dry-run
  1. 使用如下命令执行清理动作
git remote prune origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant