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

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.

主站蜘蛛池模板: 逊克县| 揭阳市| 洛川县| 日土县| 陆河县| 瓦房店市| 塘沽区| 海安县| 老河口市| 永丰县| 大埔区| 米易县| 明水县| 林芝县| 隆化县| 吴川市| 贞丰县| 西丰县| 泗水县| 华阴市| 都匀市| 霍城县| 青岛市| 新干县| 蕲春县| 木里| 都昌县| 上饶市| 长汀县| 阜南县| 阿巴嘎旗| 怀来县| 巴楚县| 吴堡县| 辉县市| 雷州市| 阳曲县| 渭源县| 文昌市| 额尔古纳市| 凤阳县|