1. Checkout Remote Branches:
$ git checkout -t origin/haml
2. List Remote Branches:
git branch -r # remote branches
git branch -a# all branches
git branch # local branches
3. 恢復刪除的或者修改的文件
git checkout-- file-name # 加'--',表示後面的是文件名,而不會把它當作命令的其他類型的參數,比如tag名
git reset commit-id 恢復到某次commit,如HEAD
git reset--soft commit-id 恢復到某次commit,保留至此commit之後的修改在staging
4. 刪除本地/遠程 branch
To delete a local branch
git branch -d the_local_branch
To remove a remote branch (if you know what you are doing!)
git push origin :the_remote_branch
參考:https://makandracards.com/makandra/621-git-delete-a-branch-local-or-remote
5.checkout -b
創建並切換到新分支,當前分支爲之前的工作區的內容。
6. git stash
保存當前工作區,包括stage(git add後,但沒有commit的)。
stash不屬於某個branch,可以checkout任意branch,然後apply。
git stash : 保存當前修改
git stash list : 查看當前有那些stash
git stash pop: 使用stash棧頭
git stash apply stash@{0} : 使用某個stash
7. git push local branch to origin
git push -u origin branch_name
8. git push --force remote_name remote_branch
rewrite the remote branch
9. remote
git remote add origin [email protected]:caius/foo.git
git remote -v
10. 查看某個文件的修改歷史
git log --pretty=oneline file-name
11. 查看某個cmmit修改的文件
git show --pretty="format:" --name-only file-name
http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git
FAQ:
1. Can I destroy and recreate a Git remote branch in one command?