checkout remote branch

git fetch origin && git checkout --track origin/branch_name


ssh -T -ai ~/.ssh/id_rsa [[email protected]](

会打印出id_ras是否被某个repo作为deploy key.


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:

  1. No metadata about a commit (such as date, author, commit message, etc.) ;
  2. No statistics about the diff (diffstat, such as x files changed, y insertions(+), z deletions(-));
  3. 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


export GIT_SSH_COMMAND='ssh -i ~/.ssh/your_private_key'


文章版权归 FindHao 所有丨本站默认采用CC-BY-NC-SA 4.0协议进行授权|
转载必须包含本声明,并以超链接形式注明作者 FindHao 和本文原始地址: