GIT常用命令

 

清除本地缓存:

git rm -r --cached .

设置代理:

clone 代理:git clone -c http.proxy=http://10.101.1.6:80/ https://github.com/haad/proxychains

全局设置,git config --global http.proxy ip:port

当前工程设置,git config --local http.proxy ip:port

取消代理:

git config --global --unset http.proxy

git config --local --unset http.proxy

(https.proxy)

当需要将远程项目和本地的一个不同项目pull下来合并时,会报错:fatal: refusing to merge unrelated histories

用以下命令可解决:

git pull --allow-unrelated-histories origin master

 git remote add origin https://github.com/TopJames/SomePractives.git

让当前的本地工程添加一个远程指向到https://github.com/TopJames/SomePractives.git,该指向的名字叫做origin

git撤销commit,但未git push的命令

 


1、找到之前提交的git commit的id
git log
找到想要撤销的id
2、git reset –hard id
完成撤销,同时将代码恢复到前一commit_id 对应的版本
3、git reset id
完成Commit命令的撤销,但是不对代码修改进行撤销,可以直接通过git commit 重新提交对本地代码的修改

 

 

git add 命令添加所有改动内容

git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件。

注意 -A 选项后面还有一个句点。 git add -A表示添加所有内容, git add . 表示添加新文件和编辑过的文件不包括删除的文件; git add -u 表示添加编辑或者删除的文件,不包括新添加的文件。

git push/pull远程指定分支

git push/pull origin test

#test为子分支

git clone远程指定分支

git clone -b 分支名 URL

git rm删除远程文件

使用 git rm 命令即可,有两种选择.

         一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;

         一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)

    假如你有文件不小心commit到了服务器那么你想要删除它,可以使用:

[plain] view plaincopy
 
  1. git rm -- cached "路径+文件名"  


    接下来:

[plain] view plaincopy
 
  1. git commit -m "delete file"  


    最后:

[plain] view plaincopy
  1. git push
原文地址:https://www.cnblogs.com/Starshot/p/7721798.html