LoginSignup
0
0

More than 1 year has passed since last update.

git 的一些特殊用法

Last updated at Posted at 2021-05-30

同步github PR到本地

比如同步bitcoin的第11000个PR https://github.com/bitcoin/bitcoin/pull/11000
在项目目录下执行git fetch origin pull/11000/head:pr_11000

通用格式:git fetch <remote> pull/11000/head:<branch_name>

GitHub开启二次验证后, 无法通过https的方式clone项目

GitHub 开启二次验证后, 无法通过 https 的方式clone项目

申请 Personal access tokens,申请的token 当做用户密码,就能正常clone项目。

Github绑定GPG签名

clone 单独的branch

git clone <repo_url> --branch <tag_name> --single-branch

git clone --branch gh-pages https://github.com/Semantic-Org/Semantic-UI-Docs docs-gh-pages --single-branch 克隆 Semantic-UI-Docs 的 gh-pages 分支到 本地的docs-gh-pages 文件夹

获得两个版本间所有变更的文件列表

git diff  --name-status 052eaed16a <tag_name>

git diff 052eaed16a <tag_name> --stat

submodule

Git Submodule 允许一个git仓库,作为另一个git仓库的子目录,并且保持父项目和子项目相互独立。

git submodules

git submodule update --init # clone 后自动初始化子项目

git submodule update --remote

git clean

FBI warning: git clean -df 之后的文件无法恢复

git clean -n
是一次clean的演示, 告诉你哪些文件会被删除。 这个命令不会真正的删除文件,只是一个提醒。

git clean -f
删除当前目录下所有没有track过的文件。不会删除 .gitignore文件里指定的文件夹和文件,不管这些文件有没有被track过。

git clean -f <path>
删除指定路径下的没有被track过的文件

git clean -df
删除当前目录下没有被track过的文件和文件夹

git clean -xf
删除当前目录下所有没有track过的文件。不管是不是.gitignore文件里面指定的文件夹和文件。


参考:

https://stackoverflow.com/questions/1911109/how-do-i-clone-a-specific-git-branch
https://tecadmin.net/clone-specific-git-branch
https://segmentfault.com/q/1010000000133613
https://www.jianshu.com/p/f8a55b972972
https://stackoverflow.com/a/34919582/6132577
https://help.github.com/articles/checking-out-pull-requests-locally/
https://stackoverflow.com/a/34919582/6132577
http://www.cnblogs.com/irocker/p/git-clean.html
https://loveky.github.io/2013/12/18/git-clean/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0