更新Git:
$ git clone git://git.kernel.org/pub/scm/git/git.git
Git 自帶一個 git config 的工具來幫助設置控制 Git 外觀和行爲的配置變量。 這些變量存儲在三個不同的位置:
1./etc/gitconfig 文件: 包含系統上每一個用戶及他們倉庫的通用配置。 如果使用帶有 --system 選項的 git config 時,它會從此文件讀寫配置變量。
2.~/.gitconfig 或 ~/.config/git/config 文件:只針對當前用戶。 可以傳遞 --global 選項讓 Git 讀寫此文件。
3.當前使用倉庫的 Git 目錄中的 config 文件(就是 .git/config):針對該倉庫。
創建用戶
git config --global user.name "username"
git config --global user.email "[email protected]"
再次強調,如果使用了 --global 選項,那麼該命令只需要運行一次,因爲之後無論你在該系統上做任何事情, Git 都會使用那些信息。 當你想針對特定項目使用不同的用戶名稱與郵件地址時,可以在那個項目目錄下運行沒有 --global 選項的命令來配置。
文本編輯器
$ git config --global core.editor emacs
查看配置信息
git config --list
檢查版本
git --version
項目管理:
$ mkdir projectname #projectname項目名稱
$ cd projectname/ #打開projectname目錄
$ git init #生成git目錄
$ ls -a #查看內部文件
$ touch txtname #創建文件
$ vim txtname #打開文件
$ rm -rf .git #強制刪除.git本地倉庫
$ cd .. #回退
常見Git命令
clone Clone a repository into a new directory 克隆一個倉庫到新目錄 init Create an empty Git repository or reinitialize an existing one 創建一個空的Git存儲庫或重新初始化現有的存儲庫 > >`work on the current change (see also: git help everyday)` > 在當前的變化上工作(參見:git help everyday) >
usage: git [--version] [--help] [-C <path>] [-c name=value][--exec-path[=<path>]] [--html-path] [--man-path] [--info-path][-p | --paginate | --no-pager] [--no-replace-objects] [--bare][--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]<command> [<args>]
These are common Git commands used in various situations:
這些是在各種情況下使用的常見Git命令:
start a working area (see also: git help tutorial)
啓動一個工作區(參見:git help tutorial)
add | Add file contents to the index |
將文件內容添加到緩存區 | |
mv | Move or rename a file, a directory, or a symlink |
移動或重命名文件,目錄或符號鏈接 | |
reset | Reset current HEAD to the specified state |
將當前HEAD重置爲指定狀態 | |
rm | Remove files from the working tree and from the index |
從工作區和緩存區刪除文件 |
bisect | Use binary search to find the commit that introduced a bug |
使用二分查找找到引入錯誤的提交 | |
grep | Print lines matching a pattern |
打印符合圖案的線條 | |
log | Show commit logs |
顯示提交日誌 | |
show | Show various types of objects |
顯示各種類型的對象 | |
status | Show the working tree status |
顯示工作區文件的狀態 |
branch | List, create, or delete branches |
列出,創建或刪除分支 | |
checkout | Switch branches or restore working tree files |
切換分支或恢復工作區文件 | |
commit | Record changes to the repository |
記錄對存儲庫的更改 | |
diff | Show changes between commits, commit and working tree, etc |
顯示兩顆樹之間的差異 | |
merge | Join two or more development histories together |
合併一個或者多個分支到你已經檢出的分支中 | |
rebase | Reapply commits on top of another base tip |
將提交到某一分支上的所有修改都移至另一分支上 | |
tag | Create, list, delete or verify a tag object signed with GPG |
創建,列出,刪除或驗證使用GPG簽名的標籤對象 |
fetch | Download objects and refs from another repository |
從另一個存儲庫下載對象和參考 | |
pull | Fetch from and integrate with another repository or a local branch |
從另一個存儲庫或本地分支中獲取並與其集成 | |
push | Update remote refs along with associated objects |
更新遠程引用以及關聯的對象 |