Git Errors总结

Sourcetree 在push代码时候弹出Password Required

在用Sourcetree进行代码管理时,公司的账号老是弹窗提示需要输入密码,但是输入密码又没有任何用,经过一番摸索,找到了一个解决办法,现在分享给大家,如果你有更好的解决方法

img
解决办法

打开【偏好设置】-> 【高级】-> 对存在的当前用户进行移除

这样的话push时会让你输入用户名和密码,在次输入就可以了,目前没有啥好办法,暂时先这样解决了

img
最新方法
1、在终端(terminal)打开你的工程目录
2、输入

1
git config credential.helper store

3、拉取代码

1
git pull

4、输入用户名密码,后面就不会再提示了,搞定
5、参考
http://zhige.me/2019/01/28/2019/01/sourcetree_password_required/#more

ssh port 22: Operation timed out

Q:

1
2
3
4
5
6
7
8
9
10
11
ssh: connect to host gitee.com port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: https://hxdd.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess.task.on.code (/Users/moyan/All/GitStorehouse/hxdd/node_modules/hxdd-deployer-git/node_modules/hxdd-util/lib/spawn.js:51:21)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

A:

把git@gitee.com:name/name.git换成https://gitee.com/name/name.git

git忽略换行符

在 Git 仓库内配置 .git/info/attributes 文件

可以在 Git 仓库中新建一个名为 .git/info/attributes 的文件,并配置以下代码:

1
* text=auto !eol

这样配置后,Git 就会将所有文件自动识别为文本文件,同时忽略换行符的变化。而且这种做法的好处在于,这个文件是在 Git 仓库内部定义,不会被共享提交到远程仓库中,让其他开发者使用也是方便的。

failed to push some refs to

error: failed to push some refs to ‘‘git@xxx.com:xxx/xxx.git’’

此故障是Git在上传后的报错

处理方法 git pull origin 分支 --allow-unrelated-histories

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
PS F:\ddd> git add .
PS F:\ddd> git commit -m 'test'
[hxdd 082e6890] test
3 files changed, 3 insertions(+), 3 deletions(-)
PS F:\hxdd> git push origin hxdd
To gitee.com:jerrryWang/jerrryWang.git
! [rejected] hxdd -> hxdd (fetch first)
error: failed to push some refs to 'git@gitee.com:jerrryWang/jerrryWang.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
PS F:\hxdd> git pull origin hxdd --allow-unrelated-histories
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From gitee.com:jerrryWang/jerrryWang
* branch hxdd -> FETCH_HEAD
f9354938..3ef82a03 hxdd -> origin/hxdd
Merge made by the 'recursive' strategy.
PS F:\hxdd> git push origin hxdd
Enumerating objects: 18, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 886 bytes | 295.00 KiB/s, done.
Total 8 (delta 6), reused 0 (delta 0)
remote: Powered By Gitee.com
To gitee.com:jerrryWang/jerrryWang.git
3ef82a03..e90aaa55 hxdd -> hxdd

git pull卡死

在拉取代码的时候,git pull origin master一直无响应。

用过的处理方法(无效):

  1. 重新配置git
  2. 重新配置git密码以及github公钥
  3. 重启服务器

这样的问题,是自己本地“悬空对象”太多,及删除分支或清除stash的时候,其实这些并没有真正删除,成为悬空对象,解决方法如下两步:

git fsck --lost-found

git gc --prune=now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@allen blog]# git pull origin master


^C
[root@allen blog]# git fsck --lost-found
notice: HEAD points to an unborn branch (master)
notice: No default references
[root@allen blog]# git gc --prune=now
Nothing new to pack.
[root@allen blog]# git pull origin master
remote: Enumerating objects: 7769, done.
remote: Counting objects: 100% (7769/7769), done.
remote: Compressing objects: 100% (1487/1487), done.
* branch master -> FETCH_HEAD

借鉴于:https://blog.csdn.net/CaiFeiYueLe/article/details/95331726

大小写变更git status没有修改记录

在使用 Git 时,如果你更改了文件名的大小写(例如从 FileName.txt 改为 filename.txt),Git 可能不会检测到这种变化,导致你在 git status 中看不到任何修改记录。这是因为 Git 默认情况下是不区分文件名大小写的。

  1. 查看当前配置
    首先,检查 Git 是否区分文件名大小写:

    1
    git config --get core.ignorecase

    如果输出为 true,则表示 Git 不区分文件名大小写。

  2. 设置 Git 区分文件名大小写
    为了使 Git 区分文件名大小写,可以设置 core.ignorecasefalse

    1
    git config core.ignorecase false
  3. 检查修改
    设置完成后,运行 git status,你应该能看到文件名大小写的变化:

    1
    git status
  4. 提交修改
    现在你可以正常添加和提交修改:

    1
    2
    git add .
    git commit -m "更改文件名大小写"

处理线上文件或文件夹冲突

  1. 删除线上大写文件
    在线上仓库中删除大写文件(例如 FileName.txt)。你可以在 GitHub、GitLab 等平台上直接删除,或者通过命令行删除:

    1
    2
    3
    git rm FileName.txt
    git commit -m "删除大写文件"
    git push
  2. 删除线上大写文件夹

    1
    2
    3
    git rm -r categories/Database tags/Conda tags/Mysql
    git commit -m "删除大写文件"
    git push
  3. 同步本地仓库
    删除线上文件后,同步本地仓库以确保一致性:

    1
    git pull
  4. 重新创建小写文件
    如果本地文件已经不存在,重新创建小写文件(例如 filename.txt):

    1
    2
    3
    4
    touch filename.txt
    git add filename.txt
    git commit -m "重新创建小写文件"
    git push