你必須會的git

Git是一個分佈式版本控制/軟件配置管理軟件,原是Linux內核開發者林納斯·託瓦茲(Linus Torvalds)爲更好地管理Linux內核開發而設計。應注意的是,這與GNU Interactive Tools(一個類似Norton Commander界面的文件管理器)有所不同。

Git最初的開發動力來自於BitKeeper和Monotone。Git最初只是作爲一個可以被其他前端(比如Cogito或StGIT)包裝的後端而開發的,但後來Git內核已經成熟到可以獨立地用作版本控制。很多著名的軟件都使用Git進行版本控制,其中包括Linux內核、X.Org服務器和OLPC內核等項目的開發流程。  摘自Wikipedia


# 初始化git
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
#
# 設置換行(*unx 與 win32區別)
$ git config --global core.autocrlf input  / true (windows)
$ git config --global core.safecrlf true
#
# 爲當前 目錄 建庫 Repositories
$ git init
# 將當前特定項目文件添加到 新建庫
$ git add hello.py
# 將當前目錄下所有文件添加到 新建庫
$ git add .
# 提交更新並添加描述
$ git commit -m "First Commit"
#
# fork一個項目
$ git clone https://github.com/refinedKing/refinedking.github.io.git
#
# 查看當前 Repo 的信息
$ git status
#
# 查看當前 Branch 分支日誌信息
$ git log
$ git log --pretty=oneline
#
$ git log --pretty=oneline --max-count=2
$ git log --pretty=oneline --since='5 minutes ago'
$ git log --pretty=oneline --until='5 minutes ago'
$ git log --pretty=oneline --author=<your name>
$ git log --pretty=oneline --all
#
# 更改當前 Branch 分支的日誌記錄格式
$ git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short'
#
    讓我們看一下細節:
    --pretty="..." 定義輸出的格式
    %h 是提交 hash 的縮寫
    %d 是提交的裝飾(如分支頭或標籤)
    %ad 是創作日期
    %s 是註釋
    %an 是作者姓名
    --graph 使用 ASCII 圖形佈局顯示提交樹
    --date=short 保留日期格式更好且更短
#
# 你的 $HOME 目錄的 .gitconfig 文件中(命令別名)
vim ~/.gitconfig
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
type = cat-file -t
dump = cat-file -p
#
# 如果你的 Shell 支持別名或簡寫
vim ~/.profile
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
alias got='git '
alias get='git '
#
# 根據提交版本信息hash號,進行 Fork
$ git checkout <hash>
#
# 對當前 Fork 出的 Bransh 進行命名
$ git checkout -b greet
#
# 切換回主分支
$ git checkout master
#
# 切換回剛纔的greet分支
$ git checkout greet
#
# 與master主線合併
git merge master


後記:

關聯遠程庫  git remote add origin git@server-name:path/repo-name.git

第一次推送: git push -u origin master

遠程推送修改: git push origin master

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