git的使用詳解

1.git分支操作常用命令

    查看分支:git branch

    創建分支:git branch name

    切換分支:git checkout name

    創建+切換分支:git checkout -b name

    合併某分支到當前分支:git merge name

    刪除分支:git branch -d name

    刪除遠程分支:git push origin :name

    撤銷修改:git checkout filename

    刪除文件:git rm file

    重命名文件:git mv oldname newname

    查看狀態:git status

    添加記錄:git add file 或 git add .

    添加描述:git commit -m "miao shu nei rong"

    修改描述:git commit --amend

    同步數據:git pull

    提交數據:git push origin name

    代碼回滾:git reset --hard commit-id (--hard清除本地的所以修改,不加不會清除本地的修改)


2.git生成patch和打入patch


2.1 使用git format-patch生成所需要的patch:
    當前分支所有超前master的提交:
    

     git format-patch -M master


    某次提交以後的所有patch:
   

     git format-patch 4e16... --4e16指的是commit名

    從根到指定提交的所有patch:
    

     git format-patch --root 4e16


    某兩次提交之間的所有patch:

     git format-patch 365a..4e16 --365a和4e16分別對應兩次提交的名稱


    某次提交(含)之前的幾次提交:

     git format-patch –n 07fe --n指patch數,07fe對應提交的名稱

    故,單次提交即爲:

     git format-patch -1 07fe


git format-patch生成的補丁文件默認從1開始順序編號,並使用對應提交信息中的第一行作爲文件名。如果使用了-- numbered-files選項,則文件名只有編號,不包含提交信息;如果指定了--stdout選項,可指定輸出位置,如當所有patch輸出到一個 文件;可指定-o <dir>指定patch的存放目錄

2.2 patch的應用   

    先檢查patch文件:git apply --stat newpatch.patch
    檢查能否應用成功:git apply --check newpatch.patch
    打補丁:git am --signoff < newpatch.patch

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章