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
To remove a remote branch (if you know what you are doing!)
参考: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 git@github.com: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?