git命令

commit
branch
checkout
merge
rebase
branch -f
reset
revert
cherry-pick
rebase -i

commit

1
2
3
4
5
6
git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
[--dry-run] [(-c | -C | --fixup | --squash) <commit>]
[-F <file> | -m <msg>] [--reset-author] [--allow-empty]
[--allow-empty-message] [--no-verify] [-e] [--author=<author>]
[--date=<date>] [--cleanup=<mode>] [--[no-]status]
[-i | -o] [-S[<keyid>]] [--] [<file>…​]

git commit –allow-empty -m “empty”

merge

1
2
3
4
5
6
git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
[--[no-]allow-unrelated-histories]
[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>…​]
git merge --abort
git merge --continue

git merge master

git merge bugfix

rebase

1
git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>] [<upstream> [<branch>]]

upstream 挂载的地方
branch 操作的branch,不填默认当前分支
-i 可操作模式

rebase test script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
git init
git commit --allow-empty -m "c0"
git checkout -b bugfix
touch c1.txt
git add c1.txt
git commit -m "c1"
touch c2.txt
git add c2.txt
git commit -m "c2"
git checkout master
touch c3.txt
git add c3.txt
git commit -m "c3"
touch c4.txt
git add c4.txt
git commit -m "c4"

clean script

1
rm -rf .git

git rebase bugfix
git rebase –interactive bugfix

First, rewinding head to replay your work on top of it…
当前分支的当前节点与远程分支的节点不匹配,需要重置到远程分支的节点

https://stackoverflow.com/questions/39460635/use-git-rebase-and-i-get-nothing-to-do

在rebase和merge后处理冲突

git merge bugfix
git rebase bugfix
git rebase master bugfix
git mergetool

git merge –abort

test script

1
2
3
4
5
6
7
8
9
10
11
12
13
git init
echo "initline" > c0.txt
git add c0.txt
git commit -m "c0"
git checkout -b bugfix
echo "bugfix branch line" >> c0.txt
git add c0.txt
git commit -m "c1"
git checkout master
echo "master branch" >> c0.txt
git add c0.txt
git commit -m "c2"

修改相关配置,若需要全局,可加--global

git config –global –list
git config –global –unset mergetool.bc3.trustexitcode

1
2
3
4
5
git config  merge.tool bc3
git config mergetool.bc3.cmd "\"C:/Program Files (x86)/Beyond Compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
git config mergetool.bc3.trustExitCode true
git config mergetool.keepBackup false

clean script

1
2
3
rm -rf .git
rm *.txt

branch 、 checkout 、tag

fetch 、 pull 、push

rebase 、reset 、merge

stash

git-stash-ref
git-stash

clean

常用的命令

修改最后一个提交的消息

git commit --amend -m "New commit message."

https://linuxize.com/post/change-git-commit-message/

https://www.v2ex.com/t/368083

https://learngitbranching.js.org/?locale=zh_CN

some cmd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
`git diff --cached a.php` 可以用于查看暂存区中文件的修改·
`git diff a.php` 查看文件相比上一个提交做了哪些修改
`git diff master --stat` 显示差异文件列表

`git diff dev api-yourname > patch` (api-dev-yourname 相对于 api-dev 分支的区别)
`git apply patch` 将补丁文件应用于当前分支

`git show commitId` 查看这次提交具体修改的内容
`git show stashId` 查看 stash 的一些基本信息
`git show stashId fileName` 查看某一个文件在某一次提交中的修改

`git show commitId --stat` 查看这次修改的文件列表
`git show stashId --stat` 查看 stash 修改的文件列表

`git stash show stashId -p` 查看 stash 中修改的文件的具体内容
`git stash list` 查看 stash 列表

`git log -p -1` 查看上一次提交的修改的详细内容
`git log api dev` 在 log 里同时显示两个分支

`git fetch origin api:api && git co api` 拉取远程分支到本地并且切换到该分支
`git push --all origin` 推送所有分支到远程
`git push origin :dev` 删除远程分支

`git tag -ln` 显示 tag 列表和 tag 的注释

`git config core.fileMode false` 不检查文件权限的变化
`git config --global -e` 修改 git 全局配置

`git checkout -- markdown.md` 撤销 markdown.md 对于上一次 commit 的修改
`git checkout dev` 切换到 dev 分支

git命令
https://blog.fengcl.com/2020/03/27/git-command/
作者
frank
发布于
2020年3月27日
许可协议