其實更多的是關(guān)于gerrit的內(nèi)容
1.兩篇很不錯的git教程文章
都是由淺到深的蒲凶,很適合學習没龙。
這篇適合入門
想要提高看這篇
2.撤銷已經(jīng)push到遠端的提交
找到你的commit id,比如3df5a456 痒钝,然后執(zhí)行git revert 3df5a456
急波,此時就產(chǎn)生了一個與該id對應的提交(可以理解與之前的提交互為“反物質(zhì)”,一旦提交之后兩次就中和了)昧辽。
然后執(zhí)行git push
2.Gerrit提交時缺失change-Id的問題
有時候會有類似報錯! [remote rejected] HEAD -> refs/for/store (change https://gerrit.epbox.com.cn/5184 closed)
我出現(xiàn)這個錯誤是因為之前的commit被abandon掉了,所以提示這個change closed,解決辦法就是針對已經(jīng)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 參數(shù)來先看看會刪掉哪些文件嫁赏,防止重要文件被誤刪
git clean -nxfd
git clean -nf
git clean -nfd
4.改log顯示時間
`--date= (relative|local|default|iso|rfc|short|raw):定制后邊如果出現(xiàn)%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'
下面是效果: