Git 拉取时的命令行和遇到的问题

简易的命令行入门教程:

Git 全局设置:

git config --global user.name "XXX"
git config --global user.email "XXX"

创建 git 仓库:

mkdir project_store
cd project_store
git init
touch README.md  
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/XXX
git push -u origin "master"

 

 

 

如果你clone下来一个别人的仓库,在此基础上完成你的代码,推送到自己的仓库可能遇到如下问题:
 
问题1

modified content, untracked content错误提示的处理

获取到别人的代码仓库,保存后,在gitee发现 打开不了,
出现此种错误的原因是,在当前的git的项目中,存在其中的子文件夹隶属于别的git项目地址,即存在git文件夹。
进入克隆下的项目中,删除原有git文件信息
 

问题2

error: remote origin already exists.表示远程仓库已存在。
因此你要进行以下操作:
1、先输入git remote rm origin 删除关联的origin的远程库
2、关联自己的仓库 git remote add origin https://gitee.com/xxxxxx.git
3、最后  git push -u origin "master"    ,这样就推送到自己的仓库了。

问题3

error: src refspec master does not match any.
error: failed to push some refs to
常见原因:
1.本地git仓库目录下为空
2.本地仓库add后未commit
3.git init错误
用命令 git add + 文件名,把文件添加到仓库就行 ,然后正常push就好
 
问题4

git push -u origin master


To https://gitee.com/XXXX.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/XXXX.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.

本地是先创建的,github上的仓库是后创建的。

解决办法:

在项目根目录命令行使用git pull origin master --allow-unrelated-histories

命令行有进入编辑模式的话,输入英文冒号“:”然后输入“q”推出,commit一次。

再次同步即可。

问题5

windows 下无法 touch 新文件的依赖  ==(echo >)
#npm install touch-cli -g
 
问题6 

git clone无响应或timeout ,或者速度慢?

原地址:   https://github.com/PanJiaChen/vue-element-admin.git

1.在原地址前加   https://ghproxy.com/   ,如下所示:

git clone https://ghproxy.com/https://github.com/PanJiaChen/vue-element-admin.git 

2.在原地址前加 https://gitclone.com/  ,如下所示:

git clone https://gitclone.com/https://github.com/PanJiaChen/vue-element-admin.git 

 

问题7

从git上下载了好多代码,有时候会把仓库的地址忘掉,如何查看自己是在哪里拉取的代码呢?

解决

进入项目的根目录,执行 

git remote -v

示例如下:

C:\Users\LMG\Desktop\练习>git remote -v
origin  https://gitee.com/XXXX.git (fetch)
origin  https://gitee.com/XXXX.git (push)

 

问题8

上传项目到git,如何忽略node_modules文件夹

根目录下创建.gitignoe文件

 touch .gitignore 

添加 node_modules/

 

问题9

上传本地文件到gitee远程仓库后,发现如下情况:

文件夹显示为灰色并且无法访问,不能点击。瞬间就慌了,不着急往下看。

 

根据上面的截图来看:

首先在对应文件夹下,打开终端,
运行: git rm -r --cached "02_vue_脚手架练习"

然后在本地找到灰色文件夹中原本的.git文件手动删掉,注意显示隐藏文件去找,看上面的截图,

再然后重新 git add , commit , push 提交代码

最后成功提交文件夹,可以正常打开,如下图:

 

 

 

在这里顺便把,再次提交到远程仓库的代码给写一下:
git add 你要提交的文件 (全部提交 git add .)
git commit -m "这里面写,你提交代码时的备注,没要求"
git push
到这里应该就成功了,Good Luck!

posted @ 2023-05-09 21:08  GLin生活派  阅读(84)  评论(0)    收藏  举报