【持续更新】Git 命令集锦

本篇记录一些在工作中使用到的 Git 命令

1、 git rm --cached logs/xx.log

     参考链接 : https://segmentfault.com/q/1010000000430426

     删除已经添加到库中的文件(仅从库中删除,保留本地文件)

2、 git rm -rf --cached dirName

     删除文件夹 dirName(仅从库中删除,保留本地文件)

3、git reset HEAD^

    参考链接:http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git

    回退最近一次的commit,但是不回退当前代码修改。

    如果添加 --hard 选项,那么将回退代码修改

    每一个^代表1次commit,

    ~ 或者 ^ 均有看到过,解释为相同,但是本人仅测试过 ^

4、 git checkout <hash> -- <path1> <path2>

    强制将制定文件回退到 hash 节点

    只要使用 git log 查到了想要回退的节点,那么这个文件当时的模样,就可以查到了

5、 git pull --allow-unrelated-histories origin master

    通过  --allow-unrelated-histories 选项指定的 pull 操作,允许将无关的分支合并

    适用场景 (例): 当一个新库需要包含多个库作为包时,通过此命令进行合并

【2018/08/12】

6、git config http.proxy http://127.0.0.1:1080

    配置 http 代理,类似的还有 https 和 ftp, 参数的格式为  [protocol://][user[:password]@]proxyhost[:port],示例为只有 protocol://proxyhost:port 的情况。

     适用场景 :git 直接从 github 上拖代码拖不动,那么找个服务器吧

猜你喜欢

转载自blog.csdn.net/davied9/article/details/54696187