查看某文件的某些行的變化歷史:html
$ git log --pretty=short -u -L 2003,2005:Executor.cppgit
http://stackoverflow.com/questions/8435343/retrieve-the-commit-log-for-a-specific-line-in-a-filegithub
$ git commit -m "Something terribly misguided" (1) $ git reset --soft HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5)
This is what you want to undo緩存
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message1, or both. Leaves working tree as it was before git commit
.服務器
Make corrections to working tree files.app
git add
whatever changes you want to include in your new commit.ide
Commit the changes, reusing the old commit message. reset
copied the old head to .git/ORIG_HEAD
; commit
with -c ORIG_HEAD
will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C
option instead.fetch
git ignore 對某些文件失效:ui
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore
:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
To undo git rm --cached filename
, use git add filename
.
http://stackoverflow.com/questions/6964297/untrack-files-from-git
git update-index should do what you want
This will tell git you want to start ignoring the changes to the filegit update-index --assume-unchanged path/to/file
When you want to start keeping track againgit update-index --no-assume-unchanged path/to/file
from: http://rogerdudler.github.io/git-guide/index.zh.html
建立新文件夾,打開,而後執行 git init
以建立新的 git 倉庫。
執行以下命令以建立一個本地倉庫的克隆版本:git clone /path/to/repository
若是是遠端服務器上的倉庫,你的命令會是這個樣子:git clone username@host:/path/to/repository
你的本地倉庫由 git 維護的三棵「樹」組成。第一個是你的 工做目錄
,它持有實際文件;第二個是 暫存區(Index)
,它像個緩存區域,臨時保存你的改動;最後是 HEAD
,它指向你最後一次提交的結果。
你能夠提出更改(把它們添加到暫存區),使用以下命令:git add <filename>
git add *
這是 git 基本工做流程的第一步;使用以下命令以實際提交改動:git commit -m "代碼提交信息"
如今,你的改動已經提交到了 HEAD,可是還沒到你的遠端倉庫。
你的改動如今已經在本地倉庫的 HEAD 中了。執行以下命令以將這些改動提交到遠端倉庫:git push origin master
能夠把 master 換成你想要推送的任何分支。
若是你尚未克隆現有倉庫,並欲將你的倉庫鏈接到某個遠程服務器,你能夠使用以下命令添加:git remote add origin <server>
如此你就可以將你的改動推送到所添加的服務器上去了。
分支是用來將特性開發絕緣開來的。在你建立倉庫的時候,master 是「默認的」分支。在其餘分支上進行開發,完成後再將它們合併到主分支上。
建立一個叫作「feature_x」的分支,並切換過去:git checkout -b feature_x
切換回主分支:git checkout master
再把新建的分支刪掉:git branch -d feature_x
除非你將分支推送到遠端倉庫,否則該分支就是 不爲他人所見的:git push origin <branch>
要更新你的本地倉庫至最新改動,執行:git pull
以在你的工做目錄中 獲取(fetch) 並 合併(merge) 遠端的改動。
要合併其餘分支到你的當前分支(例如 master),執行:git merge <branch>
在這兩種狀況下,git 都會嘗試去自動合併改動。遺憾的是,這可能並不是每次都成功,並可能出現衝突(conflicts)。 這時候就須要你修改這些文件來手動合併這些衝突(conflicts)。改完以後,你須要執行以下命令以將它們標記爲合併成功:git add <filename>
在合併改動以前,你能夠使用以下命令預覽差別:git diff <source_branch> <target_branch>
爲軟件發佈建立標籤是推薦的。這個概念早已存在,在 SVN 中也有。你能夠執行以下命令建立一個叫作 1.0.0 的標籤:git tag 1.0.0 1b2e1d63ff
1b2e1d63ff 是你想要標記的提交 ID 的前 10 位字符。能夠使用下列命令獲取提交 ID:git log
你也能夠使用少一點的提交 ID 前幾位,只要它的指向具備惟一性。
假如你操做失誤(固然,這最好永遠不要發生),你能夠使用以下命令替換掉本地改動:git checkout -- <filename>
此命令會使用 HEAD 中的最新內容替換掉你的工做目錄中的文件。已添加到暫存區的改動以及新文件都不會受到影響。
假如你想丟棄你在本地的全部改動與提交,能夠到服務器上獲取最新的版本歷史,並將你本地主分支指向它:git fetch origin
git reset --hard origin/master
內建的圖形化 git:gitk
彩色的 git 輸出:git config color.ui true
顯示歷史記錄時,每一個提交的信息只顯示一行:git config format.pretty oneline
交互式添加文件到暫存區:git add -i
評論