入職的第一天,讓git命令直接給難住了,汗!使用習慣可視化的工具對於命令行早就忘記的一乾二淨。還好,回家本身練習一下,總會沒有錯的。git就不作簡介了,版本管理除了svn就是git了,其餘的都無所謂了。html
直接上命令查看全部的git命令很是簡單,直接在控制檯輸入 git,能夠看到:git
lswdeMacBook-Pro:GitHub lsw$ git 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>] The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty Git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG 'git help -a' and 'git help -g' lists available subcommands and some concept guides. See 'git help <command>' or 'git help <concept>' to read about a specific subcommand or concept.
這裏有git經常使用的命令,若是不知道命令如何使用,那麼輸入 git help <命令的名稱>,好比 git help init,而後回車,控制檯中就會輸出init命令的詳細解釋合使用說明。github
這裏只說幾個經常使用的命令:vim
一、git clone 從遠程服務器上的git版本庫克隆到本地。例子:首先進入本地的一個文件夾好比gitHubLib服務器
<p class="p1">lswdeMacBook-Pro:GitHub lsw$ git clone https://github.com/shiweihappy/LearnGItShell.git</p><p class="p1">Cloning into 'LearnGItShell'...</p><p class="p1">remote: Counting objects: 3, done.</p><p class="p1">remote: Compressing objects: 100% (2/2), done.</p><p class="p1">remote: Total 3 (delta 0), reused 0 (delta 0)</p><p class="p1">Unpacking objects: 100% (3/3), done.</p><p class="p1">Checking connectivity... done.</p>能夠看的我將遠程服務器上的 LearnGItShell這個git倉庫克隆到本地的目錄文件夾中
二、git pull --rebase 更新git的倉庫,有人就問了爲何不是用git pull,加入--rebase是什麼意思,這個問題就有點難解釋了,有時間的話我會專門寫一篇文章介紹這兩種方法的區別。若是實在想知道的話能夠網上搜索一下,具體這兩種方法哪一種更好,誰都沒法說服誰,蘿蔔白菜各有所愛吧!app
例子:ide
lswdeMacBook-Pro:<span style="font-family: monospace;font-size:18px; white-space: pre; background-color: rgb(240, 240, 240);">LearnGItShell</span> lsw$ git pull --rebase Current branch master is up to date.
三、使用vim命令建立新的文件a.txtsvn
vim a.txt工具
進入可編輯狀態 ifetch
輸入對應的內容,推出可編輯狀態 esc
保存文件 :wq
四、git status 查看倉庫的各個文件的狀態。這個命令要多使用,不管是在更新或者提交的時候,能夠查看本地的文件修改情況,防止誤修改。例子:
lswdeMacBook-Pro:LearnGItShell lsw$ git status On branch master Your branch is up-to-date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) a.txt nothing added to commit but untracked files present (use "git add" to track)
五、git add 添加文件到本地倉庫中,可使用 git add a.txt 或者 git add . 將所有文件都加入到本地倉庫中。
lswdeMacBook-Pro:LearnGItShell lsw$ git add . lswdeMacBook-Pro:LearnGItShell lsw$ git status On branch master
<p class="p1">Your branch is up-to-date with 'origin/master'.</p><p class="p2"> </p><p class="p1">Changes to be committed:</p><p class="p1"> (use "git reset HEAD <file>..." to unstage)</p><p class="p2"> </p><p class="p3"><span class="s1"> </span>new file: a.txt</p>使用add命令後,在使用status命令查看本地的文件都在本地的倉庫中了。
六、git commit命令,提交修改內容的日誌,這個命令很重要,由於經過他能夠將此次全部的修改的說明提交到git倉庫的log日誌中,這也是之後咱們查看以前修改的重要依據。例子:
lswdeMacBook-Pro:LearnGItShell lsw$ git commit -m "add a.txt" [master 9a25f4f] add a.txt 1 file changed, 3 insertions(+) create mode 100644 a.txt lswdeMacBook-Pro:LearnGItShell lsw$ ls README.md a.txt lswdeMacBook-Pro:LearnGItShell lsw$ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean
這樣咱們添加的文件的日誌就添加到本地倉庫的日誌中了,同時git提示咱們將本地的倉庫push到遠程的倉庫中。OK!繼續
lswdeMacBook-Pro:LearnGItShell lsw$ git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name. In Git 2.0, Git will default to the more conservative 'simple' behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch. See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Username for 'https://github.com': shi_weihappy@126.com Password for 'https://shi_weihappy@126.com@github.com': Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/shiweihappy/LearnGItShell.git 40ceb9f..9a25f4f master -> master
咱們輸入status命令查看一下當前的狀態:
lswdeMacBook-Pro:LearnGItShell lsw$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean
OK,遠程倉庫也提交完畢!
lswdeMacBook-Pro:LearnGItShell lsw$ git log commit 9a25f4fe7224492c7ba440c3430e27918b8fa5d8 Author: shiweihappy <shi_weihappy@126.com> Date: Tue Jan 6 22:24:10 2015 +0800 add a.txt commit 40ceb9fd3bf48bc8f351e60521761a72b9e390a4 Author: shiweihappy <shi_weihappy@126.com> Date: Tue Jan 6 22:20:11 2015 +0800 Initial commit