Git入門使用亂記(持更)

  • 初始化git倉庫,生成工做區和版本庫
git init
  • 設置用戶名與郵箱地址
git config --global user.name 'yourName'

git config --global user.email 'yourEmail'
  • 查看配置信息/具體配置信息(用戶名爲例)
git config --list
git config user.name
  • 設置默認代碼推送分支
git config --global push.default branchName

git config --global push.default master
  • 將文件提交到暫存區,存儲在對象庫中
git add fileName
  • 將內容提交到指定分支
git commit -m 'comment'
  • 查看提交記錄/日誌
git log

git log --oneline

git log dirName/fileName
  • 文件重命名
git mv oldFileName newFileName

暫存區文件的修改git

  • 文件刪除
git rm -f filename  文件強制刪除

git rm --cached filename保留本地文件
  • 操做撤銷
git revert HEAD  當前版本,從0開始計算

git revert HEAD~2 當前的第三次
  • 新建分支
git branch branchName
  • 切換分支
git checkout branchName
  • 分支合併
git merge branchName

git merge branchName --no--ff
  • 本地分支刪除
git branch -d branchName
  • 刪除遠端分支
git branch -d branchName

git push --delete origin branchName
  • 分支改動
git diff

git diff branchName1..branchName2
  • 分支重命名
git branch -m oldBranchName newBrachName
  • 建立並切換分支
git checkout -b branchName
  • 分支封存
git stash
  • 分支封存還原
git stash pop
  • 講本地倉庫代碼提交到github
<!--切換到須要提交的分支-->
git remote add origin https://github.com/username/test.git
<!--推送提交的內容-->
git push -u origin master
  • 本地分支與遠程的對應關係 `
git branch -r
  • 建立分支並關聯遠端分支
git checkout -b branchName origin/branchName
  • 移除遠程關聯
git remote remove origin

//恢復使用
git remote add origin https://github.com/username/test.git


//查看關聯狀況

git remote -v
  • git命令的別名使用
git config --global alias.ci commit
  • 證書祕鑰生成

位於~/.ssh中id_rsa和id_rsa.pubgithub

ssh-keygen -t rsa

將id_rsa.pub中內容複製到服務器/home/git.ssh/authorized中服務器

  • 忽略文件操做

在項目目錄下新建.gitignoressh

而後中.gitignore中天劍須要忽略的文件日誌

相關文章
相關標籤/搜索