Git 实用小命令收集

修改 commit
我们经常会在提交的时候拼写错误或者填入一些错误的信息,我们可以使用:

git commit --amend

如果你想修改已经提交的过的 commit 信息的话,你需要修改后:

git commit --amend
// ... edit you message
git push --force example-branch

合并 commit
有的时候我们会经常性的提交,但是等到项目开发差不多得时候在发现 commit 信息很杂乱。你可以使用下面信息将所有的 message 合并在一起:

git reset --soft "HEAD~n"
# (~n means ~1, ~2,...)
git commit --amend

快速解决冲突
我们在 merge 的时候,有的时候我们如果可以很明确使用意向的话,比如使用他人或者自己的话,我们可以通过下面命令:

# 全部使用别人的
git pull -X theirs

git checkout --theirs path/to/file
如果使用自己的:

git pull -X ours

批量删除 tag
我们很多时候都是基于 Tag 来进行 CI 集成上线的,久而久之,Tag 会很多,因此我们可能需要批量删除一些 Tag

git tag -d TAG1 TAG2 TAG3
# delete remove tag
git push REMOTE --delete TAG1 TAG2 TAG3

猜你喜欢

转载自blog.51cto.com/13932491/2313168