checkout remote branch
git fetch origin && git checkout --track origin/branch_name
检查某个key被哪个repo使用
ssh -T -ai ~/.ssh/id_rsa [[email protected]](mailto:git@github.com)
会打印出id_ras是否被某个repo作为deploy key.
生成patch
git diff > 1.patch
git diff branch_name
git diff --staged path/to/file
git diff commit_id1 commit_id2
打补丁
git apply patch_file.patch
git diff vs git format-patch
The patch file can be generated with the git diff
command, but comparing with the patch generated by the git format-patch
command, the major differences are:
- No metadata about a commit (such as date, author, commit message, etc.) ;
- No statistics about the diff (diffstat, such as x files changed, y insertions(+), z deletions(-));
- No binary diffs, only textual diffs.
如果是弄脏了branch重新交PR,rebase以后谨慎用format-patch,尤其是master branch已经更新了的情况下。
git fetch
如果是--depth 1 clone的repo, git fetch --depth 1 origin remote_branch:local_branch
git clone --depth 1
--depth 1
只clone最新的commit,不包括历史记录。
如果需要给repo contribute code,clone的时候,不要加--depth 1。
git fetch --unshallow --tags
使用--depth适合于一次性的安装,但是如果要开发,在--depth以后,可以用上面的命令获得全部commits,但是没法获得branch。要添加branch,需要执行下面的命令。
git remote set-branches origin '*'
git fetch -v --depth=1
让git自动用某个key
export GIT_SSH_COMMAND='ssh -i ~/.ssh/your_private_key'
Reference
https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch
https://docs.github.com/en/authentication/troubleshooting-ssh/error-key-already-in-use
https://stackoverflow.com/questions/4624127/what-is-the-difference-between-git-format-patch-and-git-diff
https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches
Comments