git常用命令的一些記錄

git常用命令

1.通過git log查看提交信息
git branch -a查看全部分支,git branch查看分支
git checkout -b develop創建分支

2.通過git reset --soft <版本號>重置至指定版本的提交達到撤銷提交的目的。git reset --soft aa990cff24534frg345greg435rh

3.通過git commit --amend修改提交信息:相當於會覆蓋上次提交的錯誤信息,gitk圖形界面上看不到上次提交的信息,git log也看不到之前的信息。而commit -m ''則是直接添加了一個提交信息。【只能修改commit後的信息,如果是push了的,則會引起merge,需要強制-f提交】

git commit --amend --no-edit:不做commit修改,只是合併提交。

4.解決衝突:
git rebase :多人在同一個分支上協作時,很容易出現衝突。即使沒有衝突,後push的童鞋不得不先pull,在本地合併,然後才能push成功。[把分叉的提交歷史“整理”成一條直線,看上去更直觀。缺點是本地的分叉提交已經被修改過了]

git rebase --continue:用於修復衝突,提示開發者,一步一步地有沒有解決衝突,fix conflicts and then run “git rebase --continue”
git rebase --abort會回到rebase操作之前的狀態,之前的提交的不會丟棄;
git rebase --skip則會將引起衝突的commits丟棄掉;

pick f7f4f5f6 changed my name a bit
edit 34535e updated README formatting and added blame
pick a5f4g4h3 added cat-file

5.使用如下命令添加遠程倉庫:git remote add origin [email protected]:segwgehwh

6.合併分支merge branch "develop" into master

7.版本控制系統的branch功能也很有意思,若同時修改bug,又要加入新功能,可以fork出一個branch:一個專門修bug,一個專門加入新功能,等到穩定後再merge合併
git branch bug_fix 建立branch,名爲bug_fix
git checkout bug_fix 切換到bug_fix
git checkout master 切換到主要的repo
git merge bug_fix 把bug_fix這個branch和現在的branch合併

8.若有remote的branch,想要查看並checkout
git branch -r 查看遠程branch
git checkout -b bug_fix_local bug_fix_remote 把本地端切換爲遠程的bug_fix_remote branch並命名爲bug_fix_local

9.查看repo狀態
git log 可以查看每次commit的改變
git diff 可以查看最近一次改變的內容,加上參數可以看其它的改變並互相比較
git show 可以看某次的變更

10.刪除錯誤提交的commit方法:
git reset --hard <commit_id>
git push origin HEAD --force

11.git cherry-pick <commit-id>:用於拷貝某個單獨的patch,它的靈活性更大,而rebase主要用於整個分支的一次性合併。

12.用git status查看狀態

coommit 的一些描述規範

feat:新功能(feature)
fix:修補bug
chore:構建過程或者輔助工具變動
test:增加測試
docs:文檔(documentation)
style:格式/樣式(不影響代碼運行的變動)
refactor:重構(既不是新增功能也不是修改bug)

問題

1.問題:On branch develop Your branch is up to date with 'origin/develop'

Changes not staged for commit:
modified: test.txt

no changes added to commit

解決:提交有空文件夾,可先add試試

2.問題:error: src refspec develop does not match any. error: failed to push some refs
解決:分支沒創建

3.To github.com:michaelliao/learngit.git ! [rejected]master -> master (fetch first)error: failed to push some refs to '[email protected]:michaelliao/learngit.git'hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.[這說明有人先於我們推送了遠程分支]
解決:git pull --rebase origin master
git push -u origin master

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