git基本命令

git --help
git -h
git comand --help | -h


//git配置信息
git config --global user.name "name"
git config --global user.email "email"
git config --global color.ui "always"
git config --global core.editor "vi"
git config --global merge.tool kdiff3
git config --global meregtool.kdiff3.path "/usr/bin/kdiff3“
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status


//git创建版本库
git init
git init --bare


//git克隆
git clone url [-b branchname]     //克隆git库,如果不加-b分支,克隆默认分支,一般是master分支  


//git分支
git branch feature_nova [commitid|branch|tag]       //创建分支, 后面添加参数是基于某个提交,分支或者tag创建分支
git branch      //查看本地分支
git branch -r   //查看远程分支
git branch -a   //查看本地和远程分支
git branch --merged      //查看已经merged的分支
git branch --no-merged   //查看没有merged的分支
git branch -m | -M       //重命名分支, 
git branch -d | -D       //删除分支


//git切换分支
git checkout feature_nova        //切换分支
git checkout -b feature_nova                        //创建并切换分支, 默认基于当前分支的最新节点
git checkout -b feature_nova [commitid|branch|tag]  //创建并切换分支, 后面添加参数是基于某个提交,分支或者tag创建分支
merge有冲突
git checkout --theirs|--ours file


//git添加 
git add .
git add file1 file2
git add git-*.txt


//删除文件
git rm file1    //删除的文件,需要使用git rm 才能被commit


//重命名文件
git mv oldfile newfile


//git提交
git commit -m ""     //提交时要写注释,如果没有写 -m 会弹出界面添加注释
git commit --amend   //提交到上次(以gitlog显示的内容为准)
git commit --amend --reset-author   //修改提交者未当前配置的用户信息


//git比较
git diff [files]       //显示修改文件的差异
git diff --cached        //显示暂存区的修改
git diff branch-1 branch-2 [files]    //比较分支上的不同
git diff tag-1 tag-2 [files]       //比较tag的不同


//工作区状态
git status
git status .  //当前目录下的状态


//git log
git log 
git log -p  //显示最近p次的提交历史记录
git log --stat --summary   //显示每次更新内容及汇总
git log V3..V7 //显示V3之后直至V7的所有历史记录 
git log V3.. //显示所有V3之后的历史记录。
git log –since=”2 weeks ago” //显示2周前到现在的所有历史记录。具体语法可查询git-ref-parse命令的帮助文件。 
git log stable..experimental //将显示在experimental分支但不在stable分支的历史记录 
git log --pretty=oneline     //在一行显示
git log –name-status      //示修改的文件列表及状态


//git更新代码
git pull          //更新本地分支
git pull origin develop     //更新远端develop分支到本地当前分支,使用merge模式
git pull --rebase oriign develop     //更新远端develop分支到本地当前分支,使用rebase模式


//git推送代码
git push origin feature_1             //将本地的feature_1分支推送到服务器的feature_1分支
git push origin feature_1:feature_duanyy_1   //将本地的feature_1分支推送到服务器的feature_duanyy_1分支
git push -f origin feature_1         //强制推送本地feature_1到远端的feature_1
git push origin  :feature_2          //删除远端featur_2分支


//git拉取分支
git fetch origin develop:develop


//git回退代码
git reset HEAD file 撤销缓存状态,保留修改内容
git reset CommitID file 将文件file1回退到指定版本,处于本地缓存状态,需要commit,而原始文件内容处于本地修改未缓存状态
git reset --soft CommitID 删除历史记录,文件改动保留处于缓存状态
git reset --hard HEAD|CommitID 回退到最新状态,或者指定节点,该操作删除历史记录
git reset --hard HEAD~1|HEAD~2 回退最后一(两)次提交,或者最后一(两)次merge,该操作删除历史记录


//git revert命令会让你修改注释,这时候应该标注revert的原因,
//假设你想使用默认的注释,可以在命令中加上--no-edit参数。
//另一个重要的参数是-n或者--no-commit,应用这个参数会让revert 改动只限于本地仓库,而不自动进行commit,如果想在revert之前进行更多的改动,或者想要revert多个commit,这个参数尤其好用。
git revert HEAD   //回退上次提交内容,产生一条回退记录
git revert HEAD~3     //回退倒数第四次提交内容,产生一条回退记录,如果某文件之后被修改过会产生冲突
git revert -n master~5..master~2 
Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included), but do not create any commit with the reverted changes. The revert only modifies the working tree and the index. 


//清除未跟踪文件

git clean -fd


//git merge
git merge branch | tag | commit
git merge --no-commit    //merge完不自动commit
git merge -m "comit "    //使用你提交的commit信息,不用默认的merge信息
git merge --abort      //取消本次merge
git merge -s ours branch      //如果有冲突使用我的修改

//git rebase 
git rebase develop         //rebase 本地develop分支
git rebase --continue      //继续rebase
git rebase --abort         //取消rebase
git rebase --skip          //跳过当前rebase

//查看信息
git show commitid | tag  //显示commitid 或者tag的具体信息
git blame file           //显示文件具体修改信息

//保存当前的工作现场
git stash
git stash list       //查看保存的列表
git stash pop     //不使用任何参数,会恢复最新保存的工作进度
git stash pop {id}     //恢复某次保存的工作进度

git reflog     //可以还原git reset删除的提交,$git reset --hard commitid
git tag -a lilerong -m "20141105mars"  //创建标签, -a 加标签,-m  加标签注释。
git tag lilerong                       //创建轻量级标签,不用-a,-m等参数
git tag  //列出git中现有的所有标签
git show lilerong    //git show 命令查看相应标签的版本信息,并连同显示打标签时的提交对象
git tag -f lilerong 加上-f 覆盖原有的tag
git push origin --tags 如果要一次推送所有本地新增的标签上去,可以使用 --tags 选项:$ 
推送指定的标签:$ git push origin lilerong 
 6:删除标签:  git tag -d lilerong,删除服务器标签:git push origin :refs/tags/lilerong


git 添加远程分支:
git remote add syb remotes/origin/syb










 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值