checkout remote branch
git fetch origin && git checkout --track origin/branch_name
ssh -T -ai ~/.ssh/id_rsa [[email protected]](mailto:email@example.com)
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.
如果是--depth 1 clone的repo,
git fetch --depth 1 origin remote_branch:local_branch
export GIT_SSH_COMMAND='ssh -i ~/.ssh/your_private_key'