git 常用命令

1.git status

查看当前目录下文件变化状态,红色代表有修改的文件,但是没有加入index里面

2.git add .

添加修改文件到index下,或者添加新的文件到index

3.git commit -m "....."  

添加提交信息,'..." 为提交的comment

4. git push

将本地commit的内容,push到远程分支

5.git pull 

将远程分支上面的代码同步到本地

6.git branch -a

查看当前工程的所有分支的列表

7.git branch xxx

new一个新的分支

8.git checkout xxx

切换当前分支到xxx 分支

9.git reset --hard head

reset当前分支的改动,此行为需要谨慎使用

10.git 回退之前的提交的版本

  a.git reset --hard <commitId>   // 回退某个提交版本

  b.git push -f origin <branch name>  //push 当前分支名称到远程分支

11.git 删除本地分支

git branch -D <branch name>

12.git 删除本地有,但是远程已经不存在的分支

git remote prune origin

 13.git reflog

如果log已经被reset --hard 之后,看不到之前的log的时候,可以用reflog 查看之前的所有日志

 14.git 重新设定远程仓库地址

//a.删除远程url  
git remote rm origin

//b.重新指定远程分支地址
git remote add origin <url path>

//c.push 本地分支到远程仓库
git push --set-upstream origin master

 15.解决国内访问github 慢或者无响应

   a.使用 http://tool.chinaz.com/dns?type=1&host=github.com&ip=  网站,输入github.com

    

    b.选择TTL值最小的对应的ip

    

    c.针对window用户,打开C:\Windows\System32\drivers\etc  路径,选择hosts文件,用记事本或者notepad++等编辑工具,在页面最低端添加 b 步骤中获取的ip 和网站名称,例如:

    192.30.253.112 github.com
    192.30.253.113 github.com

     d.window用户,crtl+R ,输入cmd,进入控制台,输入ipconfig /flushdns  ,刚才的修改就生效了。

16.git统计代码量

  git ls-files | grep "\.ts$" | xargs wc -l

16.git checkout remote branch

  a.git fetch

  b.git checkout <branch name>

17.Another git process seems to be running in this repository

   rm -f ./.git/index.lock

 18.git stash

  git stash 可用来暂存当前正在进行的工作, 比如想pull 最新代码, 又不想加新commit, 或者另外一种情况,为了fix 一个紧急的bug,  先stash, 使返回到自己上一个commit, 改完bug之后再stash pop, 继续原来的工作。

  基础命令:

//暂存当前改动内容,回到当前head,没有修改状态
git stash
//do some work,此时你可以做一些自动需要的工作,例如pull最新的code,或者fix bug等
//将刚才暂存的改动还原回来
git stash pop

 19.查看远程分支地址

 git remote -v 

 20.fork的代码同步远程

a.指定上游仓库
git remote add upstream <your upstream url>
//查看是否指定成功
git remote -v
b.fetch 上游仓库
c.merge你需要的分支
git merge upstream/<your branch>

 

 21.清理无用的分支  

git remote prune origin 

 

 

 

 

 

 

 

 

 

posted @ 2017-01-05 10:47  rengised  阅读(305)  评论(0编辑  收藏  举报