Git基礎操作

Git基礎操作

1. 創建版本庫

git init
git add readme.md
git commit -m 'wrote a readme.md'

2.查看當前狀態

git status

3.查看某個文件差異

git diff readme.md

4. 版本回退

// 回退到 commit_id 版本
git reset --hard commit_id
// 查看提交歷史
git log
// 重返未來,回到未來的那個版本
git reflog

5. 撤銷修改

// 放棄某個文件的修改 (未提交到遠程倉庫)
git checkout -- filename
// 回退版本, 並且放棄某個文件的修改(爲提交到遠程倉庫)
git reset HEAD filename
git checkout -- filename

6. 刪除文件

git rm test.txt
git commit -m 'delete test.txt'

7. git 配置顏色

git config --global color.ui true

8. 配置別名

// 比如 git status ---> git st
git config --global alias.st status
// 常用
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
// lg別名
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章