Git代码如何提交

本文讲解"Git代码怎么提交",希望能够解决相关问题。

1.首先需要下载git

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

Git代码如何提交

如果未安装,则会输出:

Git代码如何提交

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

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

Git代码如何提交

2.安装后需要一些配置

配置用户名和邮箱:

$ 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=truehttp.postbuffer=524288000 
https.postbuffer=524288000 
user.email=你的邮箱@qq.com 
user.name=你的用户名 
macdeMacBook-Pro:~ Artron_LQQ$

3.建立本地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 create mode 100644 GitTest.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/GitTest.xcscheme create mode 100644 GitTest.xcodeproj/xcuserdata/Artron_LQQ.xcuserdatad/xcschemes/xcschememanagement.plist create mode 100644 GitTest/AppDelegate.h create mode 100644 GitTest/AppDelegate.m create mode 100644 GitTest/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 GitTest/Base.lproj/LaunchScreen.storyboard create mode 100644 GitTest/Base.lproj/Main.storyboard create mode 100644 GitTest/Info.plist create mode 100644 GitTest/ViewController.h create mode 100644 GitTest/ViewController.m create mode 100644 GitTest/main.m create mode 100644 GitTestTests/GitTestTests.m create mode 100644 GitTestTests/Info.plist create mode 100644 GitTestUITests/GitTestUITests.m create mode 100644 GitTestUITests/Info.plist

或者不添加注释 git commit ,但是这样会进入vim(vi)编辑器

# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:#    modified:  LQQCircleShowImage.xcodeproj/project.pbxproj#    modified:  LQQCircleShowImage/TableViewCell.m                                "~/Desktop/LQQCircleShowImage/.git/COMMIT_EDITMSG" 8L, 292C

在这里可以输入更改信息,也可以不输入,然后 按住 shift + : ,输入wq 即可保存信息并退出vim编辑器;

4.建立远程库

在一些代码托管平台创建项目,例如github或者开源中国社区,这里已开源中国社区为例;

创建项目后,会生成一个HTTPS链接,如下:

Git代码如何提交

5.将本地的库链接到远

终端中输入: git remote add originHTTPS链接

$ git remote add origin https://git.oschina.net/liuqiqiang/gitTest.git

6.上传代码到远程库,上传之前最好先Pull一下,再执行命令: git pull origin master

输出:

$ git pull origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.oschina.net/liuqiqiang/gitTest
 * branch      master   -> FETCH_HEAD
 * [new branch]   master   -> origin/master
Merge made by the 'recursive' strategy.
 README.md | 1 + 1 file changed, 1 insertion(+)
 create mode 100644 README.md

即pull成功,

7.接着执行:git push origin master

完成后输出:

$ git push origin master
Counting objects: 34, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (34/34), 15.63 KiB | 0 bytes/s, done.
Total 34 (delta 3), reused 0 (delta 0)
To https://git.oschina.net/liuqiqiang/gitTest.git
  5e2dda1..537ecfe master -> master

关于 "Git代码怎么提交" 就介绍到此。希望多多支持编程宝库

Git分支怎么合并到master:本文讲解"Git分支如何合并到master",希望能够解决相关问题。git 最强大的功能之一是分支创建和合并操作。Git 允许用户创建一个新分支并将它们合并到开发代码中。此功能通过鼓励更具体、更小和更精细的 ...