git reset --soft HEAD~1
2,从当前代码创建一个新的分支hellobranch
git checkout -b hellobranch
3,列出当前repository关联的所有远程repository
git remote -v
4,列出当前所有具有远程关联分支的信息
git branch -vv
5,切换到hellobranch分支
git checkout hellobranch
6,将一个远程代码库添加到本地代码库
git remote add newrepository http://eric.fan@192.168.1.2:8080/test/testcode.git
7,将本地分支代码推送到远程,并新建一个分支
git push newrepository hellobranch
8,将当前分支同远程分支关联
git branch --set-upstream-to=newrepository/hellobranch
9,将代码整体push到远程newrepository
git push -u newrepository --all
10,将本地分支代码推送到远程新分支,并自动关联
git push -u newrepository hellobranch
11,将本地的A分支Merge到B分支
git checkout b git merge a
12,查看最近一次提交的详细信息
git log -n 1 --stat
13,查看某次指定提交的详细信息
git log 19abb0534a --stat
14,查看作者是eric,提交日期是2017-11-30日以后的日志
git log --author=eirc --after=2017-11-30
15,根据关键字过滤log
git log --grep=keyword
16,图形界面查看某个文件的提交历史
gitk src/com/java/test.java
17,查看某个文件的完整提交历史
git log --follow -p scr/com/java/test.java
18,回滚单个文件
git checkout f67959 -- src/com/java/test.java
19,显示某个标签的详细信息
git show v1.0
20,从某个特定标签创建分支
git checkout -b newbranch v1.0
21,回滚远程的commit
git reset --hard git push -f
22,stash操作备份恢复未提交代码
git stash git stash pop git stash list git stash apply stash@{1} git stash drop stash@{1}
23,远程repository删除branch后,强制更新本地分支
git remote update origin --prune
24,查看某个或者某些commit提交的文件列表
git show --pretty="" --name-only bd61ad98 git show --name-only --oneline bd61ad98 git show --name-only --oneline HEAD^^..HEAD
25,合并remote branch的commit点
git rebase -i origin/develop~5 develop git push origin +develop
26,比较两个branch的同一文件的差异
git diff develop master -- test.txt
27,Cherry pick单个commit点
git checkout master git cherry-pick 87i312i998u
28,根据commit message,在所有/当前分支查找特定的commit
git log --all --grep='test' git log --grep='test'
29,列出特定commit变更的文件列表
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id
git diff-tree -r $commit_id
Take a diff of the given commit to its parent(s) (including all subdirectories, not just the top directory)
--no-commit-id --name-only
Do not output the commit SHA1. Output only the names of the affected files instead of a full diff
--diff-filter=ACMRT
Only show files added, copied, modified, renamed or that had their type changed (eg. file → symlink) in this commit. This leaves out deleted files.
30,列出Repo中所有人的提交次数,并排序
git shortlog -s | sort -u
31, 编辑git config全局配置
git config --global --config