<menuitem id="a2222"></menuitem>
<ins id="a2222"><video id="a2222"></video></ins>
  1. <output id="a2222"><nobr id="a2222"></nobr></output>

    <tr id="a2222"><small id="a2222"><acronym id="a2222"></acronym></small></tr>

    專注IT教育14年 全國咨詢/投訴熱線:400-8080-105
    動力節點LOGO圖
    始于2009,口口相傳的IT黃埔軍校
    首頁 hot資訊 Git代碼提交的方法

    Git代碼提交的方法

    更新時間:2022-07-06 10:45:18 來源:動力節點 瀏覽1059次

    動力節點小編來告訴大家Git代碼提交的方法。

    1.首先需要下載git

    查看電腦是否安裝git,打開終端,輸入git,回車如果輸出如下,則代表已安裝了git

    如果未安裝,則會輸出:

    按照提示輸入:sudo apt-get install git即可安裝!!或者到此處下載:git下載,pkg包下載完成,雙擊安裝。

    輸入命令:git --version 可查看當前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=true
    http.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鏈接,如下:

    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教程,里面有更豐富的知識等著大家去學習,希望對大家能夠有所幫助哦。

    免費課程推薦 >>
    技術文檔推薦 >>
    返回頂部
    欧美另类人人干

    <menuitem id="a2222"></menuitem>
    <ins id="a2222"><video id="a2222"></video></ins>
    1. <output id="a2222"><nobr id="a2222"></nobr></output>

      <tr id="a2222"><small id="a2222"><acronym id="a2222"></acronym></small></tr>