RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:9:30-18:00
扫码咨询
关闭右侧工具栏
利用git提交代码的方法步骤
  • 作者:admin
  • 发表时间:2020-11-14 07:50
  • 来源:未知

这篇文章主要介绍了利用git提交代码的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

一、首先需要下载git

查看电脑是否安装git,打开终端,输入git,回车如果输出如下,则代表已安装了git

如果未安装,则会输出:

按照提示输入:sudo apt-get install git即可安装!!或者到此处下载:git下载,pkg包下载完成,双击安装。

输入命令:git --version 可查看当前git版本

二.安装后需要一些配置

配置用户名和邮箱:

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

使用 --global 修饰后设置的全局的用户,如果设置单个项目的用户,可cd到项目根目录下,执行如下命令:

$ git config user.name "Your Name"
$ git config user.email "email@example.com"

使用命令:git config --list 可查看当前用户信息以及其他的一些信息

$ git config --list
core.excludesfile=/Users/mac/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
http.postbuffer=524288000
https.postbuffer=524288000
user.email=你的邮箱@qq.com
user.name=你的用户名
macdeMacBook-Pro:~ Artron_LQQ$

三.建立本地git仓库

1. cd到你的项目目录

$ cd /Users/cjk/Desktop/myShop

2. 然后,输入git命令:

$ git init 

输出如下:

$ git init
Initialized empty Git repository in /Users/cjk/Desktop/GitTest/.git/

创建了一个空的本地仓库.

3.将项目的所有文件添加到缓存中:

$ git add . 

git add . (注意,后面有个点)表示添加目录下所有文件到缓存库,如果只添加某个文件,只需把 . 换成你要添加的文件名即可;

4.将缓存中的文件Commit到git库

git commit -m "添加你的注释,一般是一些更改信息"

下面是第一次提交时的输出:

$ git commit -m "添加项目"
[master (root-commit) 3102a38] 添加项目
18 files changed, 1085 insertions(+)
create mode 100644 GitTest.xcodeproj/project.pbxproj
create mode 100644 GitTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create mode 100644 GitTest.xcodeproj/project.xcworkspace/xcuserdata/Artron_LQQ.xcuserdatad/UserInterfaceState.xcuserstate