22

十个超级实用的git命令 - 技术小黑屋

 3 years ago
source link: https://droidyue.com/blog/2020/05/19/cool-git-skills/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

git无疑已经成为了大家代码版本控制最多的工具了,这其中有不少人是使用终端来进行操作git。这里列出一些超级实用的git脚本,希望可以对大家开发有所帮助。

建议大家讲下面的脚本内容,都保存成脚本,然后设置执行权限,将所在目录加入环境变量,这样使用起来更加方便。

查看未合并到master的分支

1
2
#!/bin/bash
git branch --no-merged master

列出最近修改过的分支

1
2
#!/bin/bash
git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'%

启用新的vim编写提交信息

执行前的准备(后续无需执行该脚本),设置vim为默认的编辑器

1
git config --global core.editor "vim"

每次执行的脚本

1
2
#!/bin/bash
git commit -a

将未提交的修改丢弃,恢复到之前的干净状态

1
2
#!/bin/bash
git reset --hard

撤销上一个git提交

1
2
 #!/bin/bash
 git reset HEAD~

未提交情况下,取消对于某个文件的修改

1
2
#!/bin/sh
git reset HEAD $1 && git checkout $1

查看暂存的差异

用来查看当我们使用git add之后的内容的差异

1
2
#!/bin/bash
git diff --cached

切回上一个分支

1
git checkout -

查找包含某个提交的分支列表

1
git branch --contains  9666b5979(commit hash)

查找包含某个提交的tag列表

1
git tag --contains 9666b5979(commit hash)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK