代码改变世界

git

2018-12-17 15:20  dandy_ni  阅读(131)  评论(0)    收藏  举报

git init  初始化项目,用git管理
git status 查看目前代码更改情况

git add 将更改提交到缓存区(由于更改项通常比较多,所有多用 git add . )

git commit -m "说明"  提交本体代码()

git remote add origin https://fsdfs.git  常用于远程服务器没有任何分支时,添加代码关联,与下一句合在一起用
git push -u origin master 推送并关联本地分支与远程分支

git pull 拉取并合并代码

git push 推送代码

git fetch 提取代码(不自动合并代码)

git checkout 切换本地分支

git checkout -b dev origin/dev 切换到服务器分支(本地没有dev分支时,如果已经用dev分支,请直接用git pull或是git fetch)

git branch [-a] 查看所有分支(服务器与本地的所有分支)

git remote show origin 查看远程分支,还有本地分支与之相对应关系等信息

git remote prune origin 删除远程仓库不存在的本地分支

git merge b 合并本地分支b到当前本地分支

git merge origin/b 合并远程分支b到当前本地分支

 

 

查看自己的用户名和邮箱地址:

  $ git config user.name

  $ git config user.email

修改自己的用户名和邮箱地址:

  $ git config --global user.name "xxx"

  $ git config --global user.email "xxx"

一次输入,后期不用再输入用户名密码:

  $ git config --global credential.helper store

 

回退命令:
$ git reset --hard HEAD^ 回退到上个版本
$ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前 $ git reset --hard commit_id 退到/进到 指定commit的sha码

强推到远程:
$ git push origin HEAD --force