git相关

其实更多的是关于gerrit的内容

1.两篇很不错的git教程文章
都是由浅到深的,很适合学习。
这篇适合入门
想要提高看这篇

2.撤销已经push到远端的提交
找到你的commit id,比如3df5a456 ,然后执行git revert 3df5a456,此时就产生了一个与该id对应的提交(可以理解与之前的提交互为“反物质”,一旦提交之后两次就中和了)。
然后执行git push

2.Gerrit提交时缺失change-Id的问题
有时候会有类似报错! [remote rejected] HEAD -> refs/for/store (change https://gerrit.epbox.com.cn/5184 closed)
我出现这个错误是因为之前的commit被abandon掉了,所以提示这个change closed,解决办法就是针对已经closed的这个commit ,删除掉其中的change-Id,操作如下:git commit --amend,然后进入到编辑界面,手动删除掉change-Id,然后再:wq,保存退出后会自动生成新的change-Id,然后就可以提交了

3.不想提交Untracked files

删除 untracked files

git clean -f

连 untracked 的目录也一起删掉

git clean -fd

连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)

git clean -xfd

在用上述 git clean 前,墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删

git clean -nxfd
git clean -nf
git clean -nfd

4.改log显示时间

`--date= (relative|local|default|iso|rfc|short|raw):定制后边如果出现%ad或%cd时的日期格式

有几个默认选项
--date=relative:shows dates relative to the current time, e.g. "2 hours ago".

--date=local:shows timestamps in user’s local timezone.
--date=iso (or --date=iso8601):shows timestamps in ISO 8601 format.
--date=rfc (or --date=rfc2822):shows timestamps in RFC 2822 format,often found in E-mail messages.
--date=short:shows only date but not time, in YYYY-MM-DD format.这个挺好用
--date=raw:shows the date in the internal raw git format %s %z format.
--date=default:shows timestamps in the original timezone (either committer’s or author’s).
也可以自定义格式(需要git版本2.6.0以上),比如--date=format:'%Y-%m-%d %H:%M:%S' 会格式化成:2016-01-13 11:32:13,其他的格式化占位符如下:
%a:Abbreviated weekday name (Fri)
%A:Full weekday name
%b:Abbreviated month name
%B:Full month name
%c:Date and time representation appropriate for locale
%d:Day of month as decimal number (01 – 31)
%H: Hour in 24-hour format (00 – 23)
%I:Hour in 12-hour format (01 – 12)
%j:Day of year as decimal number (001 – 366)
%m:Month as decimal number (01 – 12)
%M:Minute as decimal number (00 – 59)
%p:Current locale's A.M./P.M. indicator for 12-hour clock
%S:Second as decimal number (00 – 59)
%U:Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w:Weekday as decimal number (0 – 6; Sunday is 0)
%W:Week of year as decimal number, with Monday as first day of week (00 – 53)
%x:Date representation for current locale
%X:Time representation for current locale
%y:Year without century, as decimal number (00 – 99)
%Y:Year with century, as decimal number
%z, %Z:Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%%:Percent sign
如 git config --global log.date format-local:'%Y-%m-%d %H:%M:%S 星期%w'

下面是效果:

git相关_第1张图片
git log 显示时间的修改

你可能感兴趣的:(git相关)