git rename branch
http://fredchiu.wordpress.com/2011/12/28/%E9%87%8D%E6%96%B0%E5%91%BD%E5%90%8D-rename-git-branch/
假設現在有兩個 branch, master 跟 old-branch ,目前在 master ,想要把 old-branch 的名字改成 new-branch 的話,請輸入:
git branch -m old-branch new-branch
如果現在已經在 old-branch ,想要直接把名字改成 new-branch 的話,就輸入:
git branch -m new-branch
git orphan
http://stackoverflow.com/questions/5086833/how-to-create-a-branch-without-adding-all-the-existing-files
git checkout --orphan branchname
git rm -rf .
After doing that you can create, add, and commit new files and the
resulting branch will have no common history with any other branches in
your project (unless you merge them at some point).
git untrack
http://source.kohlerville.com/2009/02/untrack-files-in-git/
The following command will stop tracking but keep the
file there intact.
git rm --cached filename
git clone local
http://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system
C:\some\dir\> git clone --local file:///C:/path/to/repo my_project
git stat
http://blog.longwin.com.tw/2009/05/git-learn-initial-command-2009/
不小心修改到檔案,但卻不知道改到哪些檔案,與最後的 commit 比較,顯示修改過的檔案清單,請輸入以下指令
git diff --stat
命令列模式顯示 tree
git log --graph --oneline --all
Cherry picking a range of commits
http://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch
In some cases picking one single commit is not enough. You need, let's say three consecutive commits.
cherry-pick
is not the right tool for this.
rebase
is. From the previous example, you'd want commit
76cada
and
62ecb3
in
master
.
The flow is to first
create a new branch from feature
at the
last commit you want, in this case
62ecb3
.
git checkout -b newbranch 62ecb3
Next up, you
rebase the
newbranch
commit
--onto master
. The
76cada^
indicates that you want
to start from that specific
commit.
git rebase --onto master 76cada^
The result is that
commits 76cada
through 62ecb3
are
applied to master
.
強制更改 server 上的 branch 舊有的提交歷史,指定將 server 上特定 branch ( e.g. develop)的提交歷史紀錄,強制覆寫為本機 branch ( e.g. develop)的提交歷史紀錄
需具備該權限,才能正常執行操作
git push origin develop -f
恢復 Commit,重新提交 Commit
假如今天您修改了兩個檔案,並且新增到暫存區了,狀態如下:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: Makefile
# modified: user/easy_setup/easysetup.h
#
並且已經執行了
git commit -m “first commit”,發現訊息寫錯想要修改,可以透過 reset 方式來做,請先用
git log 方式查看訊息
commit c13eb41110a38ef7145bb8815560641697800659
Author: appleboy <appleboy.tw at gmail.com>
Date: Fri Aug 20 20:02:55 2010 +0800
first commit
Makefile | 10 ++-
user/easy_setup/easysetup.h | 157 ++++++++++++++++++++-----------------------
2 files changed, 79 insertions(+), 88 deletions(-)
這要怎麼解決才可以改變此訊息呢?
這是一個大家常用的作法,假如您想要修改 commit 訊息,或者是尚未修改好檔案,下完此指令,您會發現 reset 會幫忙把舊的 head 複製到
.git/ORIG_HEAD,如果您沒有想要重新建立 commit 訊息,您可以下
git commit -a -c ORIG_HEAD
git 會跳出剛剛的
first commit 讓您來修改,或者是自己用 git commit -m “XXXXXXX” 這樣也可以喔。
取消最後一次 commit ,提交紀錄及檔案都還原成倒數第二次 commit 的狀態
強制恢復到上一版本
上面是介紹恢復 commit 訊息,之前修改過的檔案還會存在,底下會使用 reset hard 的方式恢復到上一版本,上一版本跟此版本之間所修改的檔案,將不會存檔,git reset 參數之一
–hard
這指令意思是說,最後三個版本 (HEAD, HEAD^, and HEAD~2) 都不是您想要修改的,你也不想給其他人看見這三個版本資訊,如果您想要保存修改過的檔案,
請勿下此指令
摘錄自以下網址:
http://blog.wu-boy.com/2010/08/git-%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%EF%BC%9A%E5%88%A9%E7%94%A8-git-reset-%E6%81%A2%E5%BE%A9%E6%AA%94%E6%A1%88%E3%80%81%E6%9A%AB%E5%AD%98%E7%8B%80%E6%85%8B%E3%80%81commit-%E8%A8%8A%E6%81%AF/
如何徹底刪除 Git 中的提交(commit)
http://liuhui998.com/2010/11/06/remove_commits_completely/
git reflog expire --expire-unreachable=0 --all
git gc --prune=0
git whatchanged 可以列出比
git log 更詳細的修改列表:
運行
git log:
$ git log
commit 41b3d1cfaae0184bb8e5f27a165d51cc23867413
Author: git-tester
Date: Mon Nov 17 15:28:01 2008 +0800
master:002
commit 2d89602d0c9955824df0d2c023e447f5d98d863a
Author: git-tester
Date: Mon Nov 17 15:26:40 2008 +0800
master:001
我們能夠看到的信息有commit,author,date,commit message,但是卻不知道這次提交涉及到那些文件。
運行
git whatchanged:
$ git whatchanged
commit 41b3d1cfaae0184bb8e5f27a165d51cc23867413
Author: git-tester
Date: Mon Nov 17 15:28:01 2008 +0800
master:002
:000000 100644 0000000… fe58238… A file1
:000000 100644 0000000… fe31ac6… A file2
:000000 100644 0000000… 3b40a58… M file3
:000000 100644 0000000… bdabb41… D file4
commit 2d89602d0c9955824df0d2c023e447f5d98d863a
Author: git-tester
Date: Mon Nov 17 15:26:40 2008 +0800
master:001
:000000 100644 0000000… fe58238… A file1
:000000 100644 0000000… fe31ac6… A file2
:000000 100644 0000000… 3b40a58… A file3
:000000 100644 0000000… bdabb41… A file4
可以看到提交涉及到的文件,A — add, M — modify, D — delete
資料來源網址:
http://blog.microsuncn.com/?p=2011
顯示目前分支名
git rev-parse --abbrev-ref HEAD
git 跨平台協作,換行符號設定
git config --global core.autocrlf input# Set this setting on OSX or Linux
git config --global core.autocrlf true# Set this setting on Windows
參考資料來源:
https://help.github.com/articles/dealing-with-line-endings
http://www.kernel.org/pub/software/scm/git/docs/git-config.html
從 git status 取得工作目錄中有修改過檔案清單
git status -s|egrep -v '^ D'|egrep -o '^ M.*'|egrep -o 'M .*'|egrep -o ' .*'|egrep -o '[^[:space:]].*'