Git學習筆記(持續更新)

來源:互聯網
上載者:User

標籤:

  1. 強制同步為遠端代碼

    遠程倉庫回退了commit的情況下(第2條描述之情況),強制同步遠端代碼到本地

    #更新遠程最新的所有代碼,但是不merge或者rebase
    git fetch --all
    #直接reset到master,也就把剛才fetch的更新了
    git reset --hard origin/master
  2. 回退版本

    #回退本地版本
    git reset --hard <commit_id>
    #強制提交到伺服器

    git push origin HEAD --force 

  3. 建立分支和遠程分支

    #建立本地分支

    git checkout -b branch_name

    #推送到遠程

    git push origin branch_name

    #設定跟蹤(預設的git pull和git push,不然需要 git push origin branch_name來更新)

    #如果第一次推送時,使用git push -u origin branch_name,則可省略這一步

    #git push --set-upstream origin branch_name

    git branch -u origin/branch_name

    #共同作業者使用

    #更新遠程branch list

    git fetch origin

    #更新遠端新分支到本地,並建立本地分支

    git checkout -b branch_name origin/branch_name

    #刪除遠程分支(傳送一個null 指標到遠程分支,相當於刪除)

    git push origin :branch_name

    #刪除遠程分支之後,其他機器同步

    git fetch -p

  4. 放棄當前工作區所有的修改

    git checkout .

Git學習筆記(持續更新)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.