git 问题集

再好的记忆也经不起时间的推敲 记录是最好的良药

使用git时经常会遇到问题 有时候搜到了解决方案 下次的时候还是会遇到 所以今天开始记录一下每次使用时的问题 加深印象


1. gitee推送到远程仓库时提示错误

remote: Incorrect username or password ( access token )
fatal: Authentication failed for 'https://gitee.com/***/***.git/'
# 输入
git config --system --unset credential.helper

2. 问题:push 分支dev 时遇到问题

# 问题
To https://gitee.com/Mandy_wang/mandy_wang.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/Mandy_wang/mandy_wang.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
#解决
git checkout origin/dev //切换远程分支
git fetch origin dev // 获取远程dev分支的修改
git merge origin dev //合并远程分支 dev
git pull origin dev //更新本地的代码

3. 没有保存本地修改 就去pull

# 问题
error: The following untracked working tree files would be overwritten by merge:
# 解决办法
git stash
git pull
git stash pop

4. 本地回滚了版本 再次push时遇到的问题

#问题: 
To https://gitee.com/Mandy_wang/mandy_wang.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/Mandy_wang/mandy_wang.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
# 解决办法
git push origin dev -f // 强制让本地分支覆盖远程分支

5. 其他

git status  // 查看工作状态
git branch -a // 查看所有分支
git log // 查看版本号
git log --pretty = online // 美化显示
git reset –-hard HEAD ^   // ( ^ 表示回到上一个版本)
git reset --hard HEAD ^^ // 上上个版本
git reset –-hard 版本号 // 回退后想恢复原来的使用

git clean -f -n:查看会删除哪些文件
git clean -f:删除上一条命令显示出来的文件
git clean -fd:删除文件夹
git clean -fX:删除已被忽略的文件
git clean -fx:删除已被忽略和未被忽略的文件
posted @ 2021-03-26 13:27  Mandy-Wang  阅读(109)  评论(0编辑  收藏  举报