git使用技巧及常见问题汇总(身为码农的你不可缺少的技能)

在gitlab上新建一个project后,有如下教程提示:

1、Git global setup (初始设置,设置登录名和密码)

git config --global user.name "***"
git config --global user.email "***@stu.ouc.edu.cn"

2、Create a new repository(打开本地终端,下载并建立git链接)

git clone https://gitlab.com/DJofOUC/temp.git
cd temp
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

3、Push an existing folder(上传一个已有的项目文件至gitlab)

cd existing_folder
git init
git remote add origin https://gitlab.com/DJofOUC/temp.git
git add .
git commit -m "Initial commit"
git push -u origin master

4、Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/DJofOUC/temp.git
git push -u origin --all
git push -u origin --tags

常见问题(长期更新。。。)

1、从本地更新至仓库

git add temp_file

git commit -m "添加文件"

git push origin master

2、命令回退

git reset --hard HEAD~1

3、查看日志

git log

4、查看状态

git status

5、merge冲突

基本上只要先git pull,然后手动修改冲突,再git push即可

6、git clone 报错:error: The requested URL returned error: 401 Unauthorized while accessing http://*****

(亲测有效)

解决方法一:指定用户
git clone https://github.com/org/project.git

换成
git clone https://username@github.com/org/project.git
或者
git clone https://username:password@github.com/org/project.git

在push或者pull出出现的话,则需要更改远程地址
git remote set-url origin https://username@github.com/org/project.git

 

参考链接:

(1)git使用教程:

https://blog.csdn.net/YJG7D314/article/details/104551896

https://mp.weixin.qq.com/s/V9Nol6BFiT2dv9n3irI7bg

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值