git 常见问题
- git pull 出现
fatal: refusing to merge unrelated histories
错误1 2 3 4 5 6 7 8 9
原因:远端认为你正在‘pull’的库和本地的库没有任何关联,所以无法 merge 解决一: 1,删除本地仓库中的 .git 目录; 2,从远端把库拉下来,然后将相关的文件拷贝到本地相应的库目录中; 3,提交,推送。 解决二: 1,执行 git pull origin master --allow-unrelated-histories 命令; 2,如果有冲突,则解决冲突; 3,提交,推送。
- 在git中出现中文乱码的解决方案
1
$ git config --global core.quotePath false
- how to add a new ssh key on GitHub
- step 1: generate a new ssh key by command
ssh-keygen
in your home’s.ssh
folder1
$ ssh-keygen -t rsa -b 4096 -C "your email address"
- step 2: look for the files generated by step 1
1 2 3 4
. ├── id_rsa ├── id_rsa.pub └── known_hosts
- step 3: output the
id_rsa.pub
’s contents1
$ cat id_sra.pub
- step 4: and the add the output’s content to your GitHub see this page
- step 1: generate a new ssh key by command
- Permission denied (publickey). fatal: Could not read from remote repository.
1 2 3 4
binli@192.168.120.246: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
- add ssh public key to remote repository, if you still have the problem, see next;
- add your private key use
ssh-add
command like this:ssh-add ~/.ssh/id_rsa
, now the problem is resolved.
- no matching key exchange method found
1 2 3 4
Unable to negotiate with 192.168.120.246 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
- add the following line to your
~/.ssh/config
file1 2
Host 192.168.120.246 KexAlgorithms +diffie-hellman-group1-sha1
- add the following line to your
- 执行 git 命令长时间卡住,需要看详细日志
1
GIT_TRACE=2 git [command]
- git stash 备份部分文件
- add 并 commit 那些你不想备份的文件(例如: git add file1.js, file2.js)
- 调用 git stash –include-untracked 只会备份那些没有被add的文件
- 调用 git reset 取消已经 add 并 commit 的备份文件,继续工作