git使用記錄一:配置賬戶信息


配置的級別

  • git config --gloabal 針對當前用戶下所有的項目 設置
  • git config --local 針對當前工作區的項目來進行設置
  • git config --system 針對當前系統下所有的賬戶進行設置

配置賬戶信息

  • git config --global user.name 'soaeon' 設置昵稱
  • git config --global user.email 'soaeon@163.com' 設置郵箱
  • git config --global http.postBuffer 524288000 設置文件最大上傳容量500M
  • ssh-keygen -t rsa -C 'soaeon@163.com' 生成key :C:\Users\soaeon.ssh 將公鑰復制到gitlab/github

清除錯誤的屬性

  • git config --global --unset key(屬性名字,比如: http..postbuffer)

克隆項目/初始化倉庫

如果項目已經存在, 那么 git clone 克隆項目吧

git clone http://xxx.xxx.com/asd/asxc.git

如果項目不存在, 跳轉到項目目錄下, 初始化

git init

git 三個區的解釋

工作區: 本地的工作目錄

暫存區: commit 之后是將工作區的內容提交到 暫存區域

遠程區: remote origin 這個才是真正的提交到git的遠程倉庫了

最簡單的提交

查看文件的狀態

git status

將文件加入

git add index.html

提交

git commit -m 'commit index.html'

暫存區的文件需要修改名字

git mv 原文件名 新文件名字

git mv index.html inde.html

修改完可以直接提交到暫存區

git commit -m 'move index.html to inde.html'

通過 git log 查看最近的演變

查看git 提交的歷史

git log

以簡潔的方式查看git的log

git log --oneline

查看最近兩次的提交

git log -n2

以圖形化的方式簡單的查看提交的歷史

git log --oneline --graph

關於分支的使用

查看所有的分支

git branch

創建分支testing

git branch testing

切換到分支testing

git checkout testing

查看每一個分支最后一次的提交

git branch -v

創建並且切換到分支demo

git checkout -b demo

刪除一個分支

git branch -d hotfix

強制刪除一個分支

git branch -D hotfix

查看本地分支和遠程分支

git branch -va

將hotfix分支合並到master分支

  • 切換到master分支
  • 執行命令 合並到master git merge hotfix

如果兩個分支修改了同一個文件呢

還原場景:

  1. hotfix 分支修改 hot.html文件
  2. hotfix 提交 git add hot.html , git commit -m 'upadte'
  3. 切換到master分支 git checkout master
  4. 修改hot.html 文件 vi hot.html
  5. 提交修改 git add hot.html , git commit -m 'master update hot.html'
  6. 執行合並 git merge hotfix

這個時候 有沖突的提示:

解決方法1: git mergetool

解決方法2:使用 git status 查看狀態, 然后使用vi hot.html 編輯文件


免責聲明!

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



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