Git命令收集

1,回滚一个错误的commit

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 --pretty="" --name-status 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'
git log -i --grep='test'
git log -i --grep='test\|hello'

29,列出特定commit变更的文件列表
[code="java"]
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commit_id
[/code]
[code="java"]
git diff-tree -r $commit_id
[/code]
Take a diff of the given commit to its parent(s) (including all subdirectories, not just the top directory)
[code="java"]
--no-commit-id --name-only
[/code]
Do not output the commit SHA1. Output only the names of the affected files instead of a full diff
[code="java"]
--diff-filter=ACMRT
[/code]
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

32, 查看两次提交之间的变化

git diff commit1 commit2 --stat
git diff commit1 commit2 --numstat
git summary commit1..commit2
git log commit1..commit2 --ignore-space-change --ignore-all-space --ignore-blank-lines --numstat --pretty=tformat:

33,查看几个指定分支之间的关系

git log --graph --decorate --oneline --simplify-by-decoration A B C
gitk --simplify-by-decoration A C D

34. 指定commit创建标签

git tag V1.1.0 047db2044a6626
git push origin V1.1.0

35. git log高级用法

git log --oneline
git log --after="2020-08-08"
git log --after="2020-08-08" --before="2020-08-13"
git log --after="yesterday"
git log --after="today"
git log --before="10 day ago"
git log --after="1 week ago"
git log --after="2 month ago"
git log -p

36. git log查看指定文件

git log -p Hello.java
git log -p Hello1.java Hello2.java 

37. git log在提交的源码中查找指定字符串

git log -p -S "commons.lang3.StringUtils"

38. git 全局配置

git config --global --edit
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值