Skip to content

常用命令

创建新分支(清除all commit)

https://git-scm.com/docs/git-checkout

git checkout --orphan <new-branch>

git 修改branch名字

git branch -m <new name>

or

git branch -m <oldname> <newname>

git 挑选commit

如:在 branch dev 下,合并 prod 的commit

git cherry-pick commit1 commit2

# commits one by one
# git cherry-pick commit1 commit2 commit3 commit4 commit5
# example:
git cherry-pick 1e038f10 2f028f10 34138b11
# commits by range
# git cherry-pick A^..B
# example:
git cherry-pick 6653c90^..481981f

输出commit

tac 行反转,ORS 间隔

git log -10 --pretty="%h" | tac | awk "{print}" ORS=' '

打包

git archive --format=zip --output mpy.zip master

stash

git stash

#保存时添加说明
git stash push -m "修复登录 Bug 的未完成代码"

#查看当前所有 stash
git stash list

#取回 stash
git stash apply stash@{0}

#取回并删除 stash
git stash pop stash@{0}

#stash 某些文件
git stash push -m "stash 某些文件" path/to/file1 path/to/file2

#丢弃某个 stash
git stash drop stash@{0}

#清空所有 stash
git stash clear

#从 stash 创建分支
git stash branch my_new_branch stash@{1}