git常见问题
Easul Lv6

! [rejected] master -> master (fetch first)

折叠代码块BASH 复制代码
1
2
3
4
5
6
7
8
9
10
# 原因: 本地仓库和远程仓库版本不一致
# 1. 先拉取远程仓库, 再推送(可能覆盖本地某些文件)
git pull origin master
# 2. 先将远程仓库与本地同步, 再重新add, commit, push
git pull origin master --allow-unrelated-histories
# 3. 直接覆盖推送, 如果有他人推送的记录则直接覆盖掉
git push -f origin master
# 4. 先把远程fetch到本地然后merge后再push
git fetch
git merge

fatal: Not a valid object name: ‘master’

创建了仓库但是还没有添加文件

折叠代码块BASH 复制代码
1
2
3
4
5
6
7
8
# 查看分支发现什么都没有
git branch
# 创建并添加文件
touch README.md
git add .
git commit -m "init"
# 现在就有分支了
git branch

.gitignore不生效

折叠代码块BASH 复制代码
1
2
3
4
5
6
# git忽略目录中,新建的文件在git中会有缓存,
# 如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
git push -u origin master

参考

 评论
来发评论吧~
Powered By Valine
v1.5.2