Git实战经验技巧总结汇总(持续更新)

学编程,学架构,拓视野,欢迎访问猿视野
本文永久更新地址:https://www.yundashi168.com/375.html
求学问道讲究:知其然,知其所以然。

gitignore规则重新生效

gitignore重新生效

个人总结的gitignore忽略文件重新生效(亲测有效)


已经纳入git工作区的文件和目录,需要把.gitignore文件和【需要忽略的文件和文件目录】先移除git暂存区,否则修改的gitignore规则不会生效!

git rm -r --cached .
git add .
git commit -m "update .gitignore"

在这里插入图片描述

git强制覆盖本地分支代码

【危险操作】放弃本地修改,使用服务器代码覆盖本地的Git命令如下:

1 $ git fetch --all
2 $ git reset --hard origin/master
# pull命令相当于fetch+合并代码命令
3 $ git pull

使用master分支覆盖本地。使用其它分支,则更改第二条命令的参数。

备注:

git fetch 只是下载远程的库的内容,不做任何的合并
git reset 把HEAD指向刚刚下载的最新的版本

git本地分支推送到远程分支

远程先开好分支然后拉到本地

git checkout -b feature-branch origin/feature-branch    //检出远程的feature-branch分支到本地

本地先开好分支然后推送到远程

$  git checkout -b feature-branch    //创建并切换到分支feature-branch  
$  git push origin feature-branch:feature-branch    //推送本地的feature-branch(冒号前面的)分支到远程origin的feature-branch(冒号后面的)分支(没有会自动创建)

git 修改远程命令

# url就是你的git地址
git remote set-url url

refusing to merge unrelated histories

解决方法:执行下面的git命令

git pull origin master --allow-unrelated-histories

问题产生的原因是:本地仓库与远程仓库不是一个仓库。

参考文献:

error: The following untracked working tree files would be overwritten by merge

解决方法:执行下面的git命令

git clean -d -fx

参考资料:

github强制用户提交代码不能用账户和密码的方式

提交代码报错:

Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information

报错信息:

$ git push github master
Logon failed, use ctrl+c to cancel basic credential prompt.
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/Arisono/react-hooks-demo.git/'

解决方法:git remote set-url origin https://token@github.com/Arisono/react-hooks-demo.git/
教程参考:https://blog.csdn.net/weixin_41010198/article/details/119698015

报错原因:2021.8.13之后,github强制用户提交代码不能用账户和密码的方式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arisono

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值