Git 指令收集

git命令介紹 git

  • git簡單命令
    web

  • git init該命令用來安裝Git追溯項目更改歷史的全部工具。 工具

    git add filename fetch

    git status this

    git log
    spa

    git commit -m "comments" code

    git checkout HEAD filename: Discards changes in the working directory. (從repositorycheckout覆蓋當前工做目錄的內容) orm

    git reset HEAD filename: Unstages file changes in the staging area.(reset 'git add '以後的內容) 開發

    git reset SHA: Can be used to reset to a previous commit in your commit history.(reset到上一次commit, SHA表示SHA碼的前7位) rem


  • git branch介紹

  •         git默認只在masterbranch工做,若是想要在其餘的版本上作些實驗性的功能開發能夠用到多個branch.

    git branch: 顯示全部的branch, 最初只有 master

    建立一個新的branch : git branch new_branch

    剛建立出來的新branch 跟master是同樣的,他們是共享一樣的commit歷史。能夠用以下命令切換branch:

    git checkout new_branch

     將兩個branch 的commit代碼合併:

    git merge branch_name

     例如將new_branch的代碼merge到master的步驟:

            1. 切換到master : git checkout master

            2. merge branch: git merge new_branch

    branch任務開發完成merge到mater以後就能夠關閉new_branch了

    git branch -d new_branch


  • git團隊協做

  • clone遠程的repository:

    git clone remote_location clone_name  

    在這個命令中:

    remote_location 告訴 Git 去找找到 remote. 它能夠是一個web地址,或者是一個文件路徑:/Users/teachers/Documents/some-remote

    clone_name 是指定Git clone repository放置的路徑名

    The workflow for Git collaborations typically follows this order:

    1.Fetch and merge changes from the remote (git clone ; git merge)

    2.Create a branch to work on a new project feature (git branch)

    3.Develop the feature on your branch and commit your work

    4.Fetch and merge from the remote again (in case new commits were made while you were working) (git fetch; git merge)

    5.Push your branch up to the remote for review (git push)


    git clone: Creates a local copy of a remote.

    git remote -v: Lists a Git project's remotes.

    git fetch: Fetches work from the remote into the local copy.

    git merge origin/master: Merges origin/master into your local branch.

    git push origin <branch_name>: Pushes a local branch to the originremote.

相關文章
相關標籤/搜索