git 命令

188

1: 进行push前先将远程仓库pull到本地仓库

$ git pull origin master

#git pull --rebase origin master

$ git push -u origin master

2: 强制push本地仓库到远程 (这种情况不会进行merge, 强制push后远程文件可能会丢失 不建议使用此方法)

$ git push -u origin master -f

3: 避开解决冲突, 将本地文件暂时提交到远程新建的分支中 $ git branch [name] # 创建完branch后, 再进行push $ git push -u origin [name]

4、查看git版本信息以及git是否安装 git --verison

5、创建一个全局用户名、全局邮箱作为配置信息

git config --global user.name "your_name"

git config --global user.email "your_email@youremail.com"

6、信息可以更改,以后想要更改使用上面指令就可以。同时可以使用git config --list指令查看Git的配置信息。 git onfig --list

7、密匙 Git关联远端仓库时候需要提供公钥,本地保存私钥,每次与远端仓库交互时候,远端仓库会用公钥来验证交互者身份。使用以下指令生成密钥,如果有提示,一路点击回车。

ssh-keygen -t rsa -C "your_email@youremail.com"

常见错误

image.png

  • 出现443是网络失败问题,所以需要检查自己的网络是否有问题
  • 当souurceTree工具上传失败时,使用命令可以上传成功,所以可以借助终端命令实现上传
Your public key has been saved in /Users/apple/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Q1iLMAvv0Ms+PzH16i8lBc/F4b6cnaj8LsdVU2tNc0E 1329905627@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|  . o   .  ....E.|
|   + + +.. .o  .+|
|  . + o o+ ..  .*|
|   + . .. +.   +o|
|    +  .So  . ...|
|   .  o ..o. =.. |
|    o  o + .=.o  |
|     o. o...o    |
|      .o.o+=o    |
+----[SHA256]-----+
appledeiMac:~ apple$ 

**以上代码是生成key的终端反馈**

**下面是github给出的终端命令**
…or create a new repository on the command line

echo "# SwiftSummary" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/SuiFengLiuNian/SwiftSummary.git
git push -u origin main
…or push an existing repository from the command line

git remote add origin https://github.com/SuiFengLiuNian/SwiftSummary.git
git branch -M main
git push -u origin main

在github上git clone一个项目,在里面创建一个目录,然后git push的时候,出现报错"Everything up-to-date"

原因:

  1. 没有git add .
  2. 没有git commit -m "提交信息"

如果上面两个步骤都成功执行,还出现这个错误是因为创建的目录下是空的,目录下必须有文件才能git push上传成功。

在github上创建文件的时候,在新文件名后加/符号就是文件夹,但是这种方式只支持英文名目录,中文名目录不支持。

如果一直ssl 443 尝试一下命令

git config --global --unset http.proxy

git config --global --unset https.proxy