官术网_书友最值得收藏!

Reviewing commits

No doubt, you sometimes need to review some commits or those of others. One thing you can do is look them up in GitLab or whatever Git server you use. You can also view them in Git GUI or any Git client. However, it is also possible to look them up using the command line. The git log command lists all commits in your current branch. There are some caveats though. Since the list of commits can be very long, they will never fit in your console window. What Git does to make this manageable is page the results. You can use the Enter key to show new lines. When you want to exit the log, you have to type q (Linux style). Usually in Windows, you exit such operations using Ctrl + C, but this will not exit the log and will probably mess up your command window and leave you confused and annoyed, and ultimately make you hit the X button and restart your console:

git log

commit f90cfa90227bf1cb21d8023b03273c991fc2f471
Author: Sander Rossel <sander.rossel@gmail.com>
Date: Sun Jan 29 21:40:16 2017 +0100

Added xlsx support.

commit 475bb165299b3d85c142b03462be9f82b8fbefb1
Author: Sander Rossel <sander.rossel@gmail.com>
Date: Sun Jan 29 21:38:16 2017 +0100

Added reporting module.

commit 51eadeab96e1950f5e61273fcb3bbfb24a75e901
Author: Sander Rossel <sander.rossel@gmail.com>
Date: Sun Jan 29 21:37:07 2017 +0100

Added reporting files.

[...]
:q
[Alternatively]
(END)q

As you can see, the latest commits are at the top as those are the ones you most likely want to see. There are a couple of useful switches to log that can be very useful. The --pretty=oneline or --oneline switches are probably the ones you would use the most. It simply prints every commit on a single line, giving you a much clearer overview of the various commits. The only difference between the two is that --pretty=oneline prints the full commit hash whereas --online prints the short version. Other --pretty formats are short, full, and fuller, but you will need to use the full --pretty=[format] syntax for those. The -p switch lists all the differences in the commit. It is also possible to limit the number of results using -[some number], for example -2:

git log --oneline -p -2

Other useful switches that can help you sort the results are --skip, --since, --after, --until, --before, and --author. There are dozens of switches for log, so if you really need this kind of functionality, I suggest you look it up in the Git documentation.

主站蜘蛛池模板: 惠安县| 永济市| 湛江市| 焉耆| 竹山县| 惠州市| 达尔| 惠州市| 张掖市| 子洲县| 肃北| 东乡| 卓尼县| 龙胜| 本溪| 临清市| 东莞市| 太白县| 沙雅县| 会理县| 汉寿县| 桐城市| 崇左市| 望江县| 库伦旗| 达孜县| 辽中县| 呼伦贝尔市| 甘孜| 连江县| 分宜县| 井研县| 松潘县| 泸溪县| 通州市| 铅山县| 巨鹿县| 色达县| 龙口市| 新郑市| 沁阳市|