git pull 是到工作区还是暂存区_Git常用命令整理五(Git疑难杂症)

Git常见问题及疑难杂症本来整理在文章《Git常用命令整理二(Git托管项目)》中,今天遇到了git pull反复输入密码的问题,很清楚这个处理命令自己记录过,一时间并没有找到。

发现疑难杂症越来越多,索性单独成篇,方便各位查看。同时欢迎大家留言补充。

0、git pull每次执行都需要输入密码

进入项目中,执行以下命令

git config --global credential.helper store

1、ssh key

git push的时候不一定要生成添加ssh keys 【https的时候不用, ssh需要】

2、git push 异常【remote: HTTP Basic: Access denied。fatal: Authentication failed】

#解决问题,需要输入账号信息

git push -u origin branch

3、git 修改后的文件不git add 也可以,直接git commit why

4、git pull错误

error: 工作区中下列未跟踪的文件将会因为合并操作而被覆盖, You have not concluded your merge

# 办法一、舍弃本地代码,远端版本覆盖本地代码

git fetch --all

git reset --hard origin/branch_name

# 如果本地存在尚未跟踪的文件,不会被覆盖,可以使用git clean清理

git clean -f

# 办法二、保留本地的更改,中止合并->重新合并->重新拉取

git merge --abort

git reset --merge

git pull

5、修改文件后直接git commit就行,为啥还需要git add。

我们支持新增文件的需要先git add filename, 然后git commit filename, 但是对于修改的文件,发现不git add,直接git commit也可以,为啥不节省一步呢?困惑了很久。

后来终于弄明白了:

先说原理,git add 是添加工作区内容到暂存区; git commit 是提交暂存区的修改到本地仓库,也可以提交工作区内容到本地仓库;git push是把本地仓库修改推送到远端仓库。

即使明白原理当时还是困惑,后来实际工作中,多人开发,我们有时候需要先把工作区修改git stash暂存了【不完善不能提交,可能是写到一半的代码】,然后git fetch, git pull, 在git pop继续未完成的工作。这个时候就需要git add, 不然git stash pop 会覆盖本地修改。

坚持优秀的习惯:commit前先add, 然后fetch、pull, 在commit、push

6、分支冲突修改后,显示both modify,提交提示fatal: cannot do a partial commit during a merge

# 使用-i参数,The -i basically tells it to stage additional files before committing。具体含义待考证。

git commit -m 'add log' -i change.php

还有一种原因也会出现这个错误提示:

手工解决冲突后,提交全部文件,使用了.或./, 不带.或./即可

git commit -m 'hidoc merge hidoc-dev-w803 冲突解决' .

git commit -m 'hidoc merge hidoc-dev-w803 冲突解决' ./

7、git branch -r竟然看不到别人提交到远程的分支。

我们知道git branch -r是查看远程分支,那么别人提交到远程的分支,我们应该都能看到啊,但是我们有时候却看不到。在一个工作区新建了一个分支test_0320, push到远程仓库,当前工作区能看到,另一个工作区则看不到,如下:

原来是这样的,本地仓库中存在本地分支和远程分支列表,如果没有执行git fetch,本地的远程分支列表就不会更新,所以就看不到远程最新的分支了。

8、git commit application/* 提示pathspec ‘application/views’ did not match any files

原因是文件目录不存在,这个文件application/views存在,删除后新建可以。

9、git clone 报”The project you were looking for could not be found.”

原因分析:当前用户没在项目成员组中

# 解决方法一:在域名前面添加项目成员用户名,用他的账号clone, 需要输入密码

git clone https://用户名@git.intra.niliu.com/tv/niliu.git

# 解决方法二:在项目成员中添加这个用户。

10、git push报错The upstream branch of your current branch does not match

fatal: The upstream branch of your current branch does not match

the name of your current branch. To push to the upstream branch

on the remote, use

git push origin HEAD:master

To push to the branch of the same name on the remote, use

git push origin bugfix_rprank_0510

To choose either option permanently, see push.default in 'git help config'.

# step1

git branch --unset-upstream

# step2

git push --set-upstream origin branch_name

11、fatal: Cannot update paths and switch to branch XXX

git checkout -b vote_platform origin/vote_platform

fatal: Cannot update paths and switch to branch 'vote_platform' at the same time.

Did you intend to checkout 'origin/vote_platform' which can not be resolved as commit?

解决方法一:更新远程仓库分支

git branch -r | grep vote

git fetch

解决方法二:远程仓库分支不存在(分支名错误,分支没提交等),请先提交,确认存在。(本次遇到实际原因是vote_platform不是当前项目下的仓库分支,是两个项目)

12、git diff内容没差异

git diff app/library/Auth.php

diff –git a/app/library/Auth.php b/app/library/Auth.php

old mode 100644

new mode 100755

解决方法:

跟目录执行

git config --add core.filemode false

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值