Unable to diff files in two separate branches in Git
http://stackoverflow.com/questions/916822/unable-to-diff-files-in-two-separate-branches-in-git
git diff branch:UNREADME master:README
git difftool somebranch:UNREADME otherbranch:README (用vim比較工具查看)
View the change history of a file using Git versioning
http://stackoverflow.com/questions/278192/view-the-change-history-of-a-file-using-git-versioning
git log -p filename ( to let git generate the patches for each log entry )
git show HEAD ( get just the diff for a specific commit )
將所有新增的檔案加入:
$ git add .
http://stackoverflow.com/questions/572549/difference-of-git-add-a-and-git-add
將檔案移除
$ git rm filename
將整個資料夾移除
$ git clean -f -d
http://stackoverflow.com/questions/61212/removing-untracked-files-from-your-git-working-copy
讓某個目錄不再追蹤
$ git rm -r --cached <your directory>
http://stackoverflow.com/questions/1329291/ignoring-an-already-checked-in-directorys-contents
git移除所有刪除的檔案
Removing multiple files from a Git repo that have already been deleted from disk
http://stackoverflow.com/questions/492558/removing-multiple-files-from-a-git-repo-that-have-already-been-deleted-from-disk
http://stackoverflow.com/questions/1402776/how-do-i-commit-all-deleted-files-in-git
$ git add -u
OR
$ git add -A
在本地端還原成某個commitID狀態
$ git reset --soft HEAD^
查哪個紀錄改了什麼檔案
http://stackoverflow.com/questions/2557564/how-do-i-identify-files-directories-that-were-added-or-removed-in-a-git-commit
$ git whatchanged -n 1
http://kevyu.blogspot.tw/2011/10/git-stash.html
使用 $ git stash 暫存現在改的狀態再checkout 其他branch 繼續做其他事
查這個commit是哪個branch
How to list branches that contain a given commit?
http://stackoverflow.com/questions/1419623/how-to-list-branches-that-contain-a-given-commit
$ git branch -a --contains commit_tag
查git commit是否含有該文字
$ git log --all --grep='XXX'
--all 會查所有branch
查專案中檔案是否含有該文字(比直接grep快)
$ git grep -e XXX -e OOO
http://stackoverflow.com/questions/215718/how-do-i-reset-revert-a-specific-file-to-a-specific-revision-using-git
取出某個版本的某個檔案
Assuming the commit you want is abcde:
$ git checkout abcde file/to/restore
20130717
在checkout另個branch時,因為用ctrl+c中斷掉了,使得git reset --hard後留下一堆untracked files
如何刪除這些untracked files和資料夾:
http://stackoverflow.com/questions/61212/removing-untracked-files-from-your-git-working-copy
git clean -f -d
to be sure that also directories are gone! you can check with git status
if they are really gone.
顯示這個commit有哪些檔案被改過
http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git
$ git diff-tree --no-commit-id --name-only -r bd61ad98
或
$ git show --pretty="format:" --name-only bd61ad98
但無法顯示是新增、修改還是刪除,也無法像git pull時顯示+++-- 的示意符號
只移除某commit的修改(不是把該commit之後的commit改變都移除)
$ git revert commmitId
GIT複製別人本地端的branch
http://www.ptt.cc/bbs/Linux/M.1387124688.A.38A.html
方法1:
$ git remote add jack ssh://jack.s.ip/home/jack/repo # 使用git remote rm jack 移除jack這個remote
$ git fetch jack
$ git checkout -b local_branch jack/local_branch # 在本地開local_branch,內容為jack/local_branch
若jack和master裡面有同樣名字的branch(ex. dev_branch),在git pull時pull到master(之前加入)的dev_branch
方法2:
$ git diff master local_branch > local_branch.diff # git diff commitId_old commitId_new
$ git checkout -b local_branch master
$ git apply local_branch.diff
$ git commmit -am "Apply patch from Jack's local_branch" # -am 自動add且commit