Git基礎入門(七)Git撤銷操做和遠程倉庫管理

撤銷操做:git


注意:Git的有些撤消操做是不可逆的。 這是在使用Git的過程當中,會由於操做失誤而致使以前的工做丟失的少有的幾個地方之一github


取消暫存的文件服務器


git add a.py b.py 網絡

git status ide

    On branch masterfetch

    Changes to be committed:url

      (use "git reset HEAD <file>..." to unstage)           #提示如何撤銷spa


    modified:   a.py命令行

    modified:   b.pyrem


git reset HEAD b.py                                         #取消暫存b.py

    Unstaged changes after reset:

    M b.py


git status 

    On branch master

    Changes to be committed:

      (use "git reset HEAD <file>..." to unstage)


    modified:   a.py


    Changes not staged for commit:

      (use "git add <file>..." to update what will be committed)

      (use "git checkout -- <file>..." to discard changes in working directory)         #提示能夠撤銷對文件的修改


    modified:   b.py




撤消對文件的修改

    git checkout b.py

    git status 

        On branch master

        Changes to be committed:

          (use "git reset HEAD <file>..." to unstage)


        modified:   a.py


git checkout -- [file] 是一個危險的命令,若是執行了這個命令你對那個文件作的任何修改都會消失





遠程倉庫:

    遠程倉庫是指託管在因特網或其餘網絡中的你的項目的版本庫,遠程倉庫能夠有多個,一般有些倉庫對你只讀,有些則能夠讀寫

    管理遠程倉庫包括瞭解如何添加遠程倉庫、移除遠程倉庫、管理不一樣的遠程分支並定義它們是否被跟蹤等等







查看遠程倉庫

    git remote              #查看當前全部的遠程倉庫

        origin              #origin 是Git給你克隆的倉庫服務器的默認名字


    -v選項,顯示遠程倉庫的簡寫與其對應的URL

    git remote -v

        origin https://github.com/libgit2/libgit2 (fetch)

        origin https://github.com/libgit2/libgit2 (push)




添加遠程倉庫

git remote add <shortname> <url>            #添加一個新的遠程Git倉庫,同時指定一個簡寫


git remote add test https://github.com/huyuan1999/17-10-22.git          #添加遠程倉庫


git remote -v

    origin https://github.com/libgit2/libgit2 (fetch)

    origin https://github.com/libgit2/libgit2 (push)

    test https://github.com/huyuan1999/17-10-22.git (fetch)

    test https://github.com/huyuan1999/17-10-22.git (push)



如今能夠在命令行中使用test來代替整個URL

    git fetch test          #拉取遠程倉庫中的信息(本地工做目錄中沒有的信息)




從遠程倉庫中抓取與拉取

    git fetch [remote-name]     #拉取遠程倉庫中的數據(不會自動合併分支)

    若是使用clone命令克隆了一個倉庫,並將其添加爲遠程倉庫默認以origin爲簡寫。因此git fetch origin會抓取克隆後新推送的全部數據


    git pull [remote-name]      #自動的抓取而後合併遠程分支到當前分支

    默認狀況下git clone會自動設置本地master分支跟蹤克隆的遠程倉庫master分支,運行git pull一般會從克隆的服務器上抓取數據並自動嘗試合併到當前分支



推送到遠程倉庫

    git push [remote-name] [branch-name]            #推送指定分支到服務器中

    git push test master              #git默認使用github作爲遠程倉庫服務器,若是想要推送到遠程倉庫則須要有對應的帳號和密碼




查看遠程倉庫


git remote show test

    * remote test                               #本地簡寫

      Fetch URL: https://github.com/huyuan1999/17-10-22.git

      Push  URL: https://github.com/huyuan1999/17-10-22.git

      HEAD branch: master                       #處於的分支                

      Remote branch:

        master tracked                          #掌握跟蹤

      Local ref configured for 'git push':

        master pushes to master (up to date)




遠程倉庫的移除與重命名

    git remote rename test hu               #重命名

    git remote

        origin

        hu



    git remote rm hu                        #移除

    git remote

        origin

相關文章
相關標籤/搜索