继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

我的Git的初步使用过程

奋斗奋斗坑
关注TA
已关注
手记 14
粉丝 19
获赞 132

安装git

配置秘钥

打开git bash

输入ssh-keygen –t rsa –C "email"

完成后会在用户目录下建立.ssh目录,且生成秘钥文件id_rsa、id_rsa.pub

打开id_rsa.pub(公钥)文件,将内容全部复制(重要)

打开github,登录,进入setting->SSH and GPG keys,具体额参考文档:https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

配置全局参数

打开Git bash

配置用户名: git config –global user.name "username"

配置邮箱: git config –global user.email "email"

git命令
  • 在本地当前目录下,将该目录初始化为一个git仓

git init;

  • 克隆个仓到本地

git clone [-b branch_name] git@github.com:git_username/pro_name.git

git remote
//给当前仓添加远程仓
git remote add repo_name git@github.com:git_username/pro_name.git
//修改远程仓在本地仓的命
git remote rename cur_repo_name new_repo_name
//移除仓
git remote remove repo_name
//查看远程仓
git remote -v
git [push|pull]
//将当前本地的分支(与远程分支同名)的推送到远程仓上
git push repo_name 远程分支
//将本地分支推送到远程分支上
git push repo_name 本地分支:远程分支
//删除远程仓上的分支
git push repo_name :远程分支

//从远程分支上拉取代码
git pull repo_name 远程分支
git基础命令
//切换分支
git checkout branch_name
git checkout -b local_branch_name [repo_name/branch_name]
//查看当前仓状态,如是否有文件修改
git status
//将变动的文件从工作区存放到暂存区
git add -A
//将暂存区的文件提交到仓里
git commit -m "commit注释"
//修改提交注释
git commit --amend
// 查看提交记录
git log
//查看分支
git branch
//修改本地分支名
git branch -m cur_branch_name new_branch_name
//删除本地分支
git branch -[d|D] branch_name
git stash
// 将修改的文件储藏起来,随时可以重新应用
git stash save "注释"
// 查看stash记录
git stash list
//将储藏的修改恢复到工作区里,但pop方式会取出stash@{0}并将其移除
git stash pop
// 将对应stash的number从储藏里获取出来,但不移除
git stash apply stash@{number}
//将对应stash的number从储藏里移除
git stash drop stash@{number}
git reset
//更改commit信息,但不覆盖工作区、暂存区的代码
git reset --soft 
//代码回退到两个提交前或10个提交前,^代表上一个提交,会更改工作区、commit的信息
git reset --hard [head^^|head~10]
git其他命令
//提取fetch远程分支数据
git fetch repo_name branch_name
//关联分支--set-upstream
git branch --set-upstream branch_name repo_name/branch_name
打开App,阅读手记
3人推荐
发表评论
随时随地看视频慕课网APP

热门评论

看不懂,实在不知道下了这个怎么办啊啊http://img2.mukewang.com/5a4c75f10001facc04710377.jpg


查看全部评论