[Git] Git操作命令

基础操作

 

git配置

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

创建文件夹与进入

mkdir learngit
cd learngit

设置当前位置为git仓库

git init

添加至仓库(又名版本库)

git add readme.md
git commit -m "wrote a readme file for comment" 

信息查看

git status                  #当前状态
git log 
git log --pretty=oneline    #列表查看

 

远程仓库.

1. 添加SSH

#创建SSH key(主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件):
ssh-keygen -t rsa -C "youremail@example.com"

#登陆GitHub,“Account settings”——“SSH Keys”
#点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容。

2. 关联

git remote add origin git@github.com:******/#####.git

3. 添加推送

git push -u origin master(第二次就不用-u了)

推送到其他分支(并命名)
git push origin dev

4. 克隆

git clone git@github.com:******/#####.git

5. 查看远程库信息

git remote
#详细
git remote -v

 

版本控制

#到过去:
git reset --hard HEAD^

HEAD //表示当前版本

HEAD^ 和 git reset // 上一个版本

HEAD^^ //上上一个版本

HEAD~10 //前10个版本

#回未来(利用commit的id):
git reset --hard 3628164

#可以查到id(它记录你的每一次命令)
git reflog

#可以查看提交历史 
git log

 

分支管理

查看分支:git branch -a

创建分支:git branch <name>

切换分支:git checkout <name>

创建+切换分支:git checkout -b <name>

合并某分支到当前分支:git merge <name>

删除分支:git branch -D <name>

 

参考资料

https://blog.csdn.net/qq_32115439/article/details/79357615

转载于:https://www.cnblogs.com/clemente/p/10118917.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值