git常用命令备忘, 遇到一个记一个,不断更新ing
0. git clone xxx
克隆远端代码到本地(一般只在第一次执行)
1. 远端创建新分支后,更新远端分支列表到本地:
git remote update origin --prune
另外,如果远端新建了一个分支testBranch, 而本地没有这个分支,可以通过如下命令更新:
git checkout -b testBranch origin/testBranch
2. 删除远端分支(慎用)
git push origin --delete BranchName
3. 删除本地分支
git branch --delete BranchName
4. 创建tag分支
git tag v1.0.0
5. 对暂存区进行暂存,查询,恢复,清除
git stash
git stash list
git stash pop
git stash clear (慎用哈,git stash clear后用git stash list就看不到任何结果了)
6. 修改本地分支名
git branch -m old_name new_name
7. 查看已经commit但没有push的内容
git log BranchName ^origin/BranchName
8. 将已经commit的内容回退到某commit_id版本
git reset --hard commit_id (注意,此命令会让工作区和暂存区的内容丢失哦。也就是说, 如果你git add, 然后git commit, 然后用git reset来回退, 那么你所做的修改都将丢失。 当然, 这种丢失是可以通过git reflog找回来的)
9. 分支查看
git branch或git branch -v
10. 当前分支为A, 需要把分支B合并到A
git merge B
11. 比较两个分支有哪些文件有差异
git diff A B --stat