搜索

【Git】本地项目同步提交代码

喃叽 喃叽

1️⃣ 选择要上传的本地项目/usr/uploads/2020/11/3695386577.png2️⃣ 配置自己的身份,这样在提交代码的时候就能知道是谁提交的

   $ git config --global user.name "名字"
   $ git config --global user.email "邮箱地址"

3️⃣新建一个【.git】控制版本

   $ git init/usr/uploads/2020/11/1713933876.png本地仓库建立完成。 仓库建立完成之后就可以提交本地代码了,这里只需要用到两个命令,add添加和commit提交

4️⃣ 提交文件

   $ git add . //是提交所有
   $ git add +文件名 //是提交单个文件
   $ git add .

> warning: LF will be replaced by CRLF in WebContent/index.html.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/login.html.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/login.jsp.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/password.jsp.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/regist.html.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/regist.jsp.
> The file will have its original line endings in your working
> directory.
> warning: LF will be replaced by CRLF in WebContent/update.jsp.
> The file will have its original line endings in your working
> directory.

5️⃣ 提交版本
git commit -m "todolist v1.0"是提交。 这里要在-m参数后面加上提交参数,很重要,不然会被认为不合法不能提交

   $ git commit -m "todolist v1.0"

> [master c509c83] jdbc v1.0
> 19 files changed, 417 insertions(+)
> create mode 100644 .classpath
> create mode 100644 .project
> create mode 100644 .settings/.jsdtscope
> create mode 100644 .settings/org.eclipse.jdt.core.prefs
> create mode 100644 .settings/org.eclipse.wst.common.component
> create mode 100644
> .settings/org.eclipse.wst.common.project.facet.core.xml
> create mode 100644
> .settings/org.eclipse.wst.jsdt.ui.superType.container
> create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name
> create mode 100644 WebContent/META-INF/MANIFEST.MF
> create mode 100644 WebContent/WEB-INF/web.xml
> create mode 100644 WebContent/index.html
> create mode 100644 WebContent/login.html
> create mode 100644 WebContent/login.jsp
> create mode 100644 WebContent/password.jspcreate mode 100644
> WebContent/regist.html
> create mode 100644 WebContent/regist.jsp
> create mode 100644 WebContent/ulist.jsp
> create mode 100644 WebContent/update.jsp
> create mode 100644 mydb.sql

6️⃣ 本地创建SSH key

   $ ssh-keygen -t rsa -C "847461291@qq.com"

1.一路回车,不需要输入。
2.成功的话会在~/下生成.ssh文件夹,进去,复制id_rsa.pub文件内容
3.添加SSH Key/usr/uploads/2020/11/408505930.png单击“Add SSH key”/usr/uploads/2020/11/3834870531.png7️⃣ 本地仓库连接git上

   $ git remote add origin git@github.com:/ly-kris/todolist.git

> 提示出错信息:fatal: remote origin already exists.    
> 解决办法如下:    
> 1、先输入$ git remote rm origin    
> 2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git
> 就不会报错了!    
> 3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config
> section 'remote.origin'. 我们需要修改gitconfig文件的内容    
> 4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
> 5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

8️⃣ 上传本地仓库

   $ git push -u origin master

> 提示出错信息:error:failed to push som refs to .......    
> 解决办法如下:    
> 1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来    
> 2、再输入$ git push origin master    
> 3、如果出现报错 fatal: Couldn't find remote ref master或者fatal: 'origin' does
> not appear to be a git repository以及fatal: Could not read from remote
> repository.    
> 4、则需要重新输入$ git remote add origingit@github.com:djqiang/gitdemo.git
> Username for 'https://github.com': ihadron
> Counting objects: 25, done.
> Delta compression using up to 4 threads.
> Compressing objects: 100% (20/20), done.
> Writing objects: 100% (25/25), 6.33 KiB | 0 bytes/s, done.
> Total 25 (delta 5), reused 0 (delta 0)remote: Resolving deltas: 100%
> (5/5), done.
> To https://github.com/ihadron/jdbc.git
> 7a049ec..c509c83  master -> master
> Branch master set up to track remote branch master from origin.

本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。

查看目录

目录

来自 《【Git】本地项目同步提交代码》

评论区



最新文章