Git使用筆記


1. git fetch --prune                   清理遠程沒有的本地分支

2. git branch -d  branchName    刪除本地分支

3. git branch |grep 'branchName' |xargs git branch -d    批量刪除本地匹配到的branchName的git分支

4. git checkout -- file  撤銷工作區的修改

5. git config core.ignorecase false   讓git 對文件大小寫敏感

6. git 錯誤 " bad index file sha1 signature fatal: index file corrupt"

  解決方案: 刪除 .git/index , 執行git reset 命令

7. git reset --hard HEAD  撤銷還沒commit的merge,或者放棄工作區的改動

    git reset --hard  commit-id 回滾到commit-id

8. git reset HEAD <file> 將文件從暫存區撤銷

9. git log 查看提交記錄

10. git reflog 查看所有操作記錄

11. git push origin :branch-name 刪除遠程分支

12. git push origin -u branch-name 將本地分支推送到遠端並建立連接

13. git remote -v  查看遠程倉庫地址

14. 設置用戶名和郵箱: git config --global user.name 'name' ,  git config --global user.email 'xxx@xxx.com'

15.  在本機生成RSA, 公鑰: ssh-keygen -t rsa -C "you@email.com'

16.  更改push 模式, git config -- global push.default simple 或者 git config --global push.default matching

17.  查看提交日志: git log --oneline --graph -author='authorName'

18.  查看某一個文件的提交日志: git log -p filename, git log -p 查看所有提交的詳細文件修改

19 . 查看某一個文件的某幾行提交日志: git log -L 1,10:filename

20.  查看工作區某個文件所做的改動與暫存區比較: git diff filename

21.  查看暫存區和上次提交之間的區別: git diff -cached filename

22.  刪除遠程分支: git push origin :remote-branch

23. 比較當前分支與另一個分支的文件差異: git diff branch-name fileName

24. 查看另一個分支上的某一個文件: git show branch-name:fileName

25. 合並另一個分支的某一次提交: git cherry-pick commitId

26. 修改最近的提交說明:git commit --amend -m 'commit description'

27. 顯示工作區根目錄 git rev-parse --git-dir

28. 相對於工作區根目錄的相對目錄:git rev-parse --show-prefix

29.顯示當前目錄后退到工作區的根目錄深度:git rev-parse --show-cdup

30. 編輯git配置文件:項目配置git config -e  全局配置 git config -e --global, 系統配置 git config -e --system

31. 獲取配置項: git config core.ignorecase, 設置配置項:git config core.ignorecase false

32. 創建版本庫: git init 或者 git init dirname (創建工作區,並在此目錄下創建版本庫)

33. 設置別名: git config --global alias.st status , git conifg --global alias.ci commit 

34. 顯示某一個提交所改動的文件: git show --stat commitId

35. 通過配置全局git ignore 文件而忽略文件:git config --global core.excludesfile ~/.gitignore

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM