1. 常用操作
设置默认编辑器为vim
1 | git config --global core.editor "vim" |
终端显示中文乱码
1 | git config --global core.quotepath false |
Convert remote’s URL from https
to ssh
:
1 | # To check if remote's URL is ssh or https |
Untrack files and don’t change working directory:
1 | git rm --cached [filename]# untrack specified file |
Reset
1 | # reset staging area and reset working directory to match last commit |
Clean files:
1 | # Show which files would be removed from working directory |
Append changes to last commit:
1 | git commit --amend |
Display commits
concerned with the specific file:
1 | git log -- <file> |
Diff
1 | # show difference between working directory and last commit |
Stash
1 | git stash |
Patch
1 | git format-patch <commit-id-head> |
Reflog
1 | git reflog |
Tag
1 | git tag -a v0.1 -m "" |
CherryPick
1 | git cherry-pick A^...B |
Checkout
1 | git checkout branch_name/commit_id/tag_name -- file_name |
2. 常见问题
file mode changes
That looks like unix file permissions modes to me (755
=rwxr-xr-x
, 644
=rw-r--r--
) - the old mode included the +x (executable) flag, the new mode doesn’t.
1 | old mode 100755 |
解决思路:
Setting core.filemode to false in order to get rid of the issue:
1 | git config core.filemode false |
部分仓库下载缓慢/失败问题
方法一
对于不包含submodule的仓库,出现这种问题后,从网页版GitHub中下载源码即可。
方法二
对于包含submodule的仓库,一般是主仓库可以下载,但是其submodule下载失败。此时,可以在clone主仓库后,分别clone每个子仓库,再将其放置到父仓库对应的目录下,然后通过git reset --hard commit_id
将子仓库切换到对应版本。
1 | git clone xxx.git repo-a --recursive # failed |
方法三
除了上述两种方法外,可以借助我的工作台 - Gitee.com解决该问题。操作时首先将需要clone的仓库从GitHub中fork到Gitee中,然后从Gitee clone即可。对于包含submodule的仓库,可以将其submodule均fork到Gitee,并修改.submodule
中对应仓库的路径为Gitee下的路径(注意此处路径结尾不包含.git
字段).