Skip to content

Instantly share code, notes, and snippets.

@shm007g
Last active November 23, 2019 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shm007g/6aad75db6c9fb30a1cacdd3befaf0e0d to your computer and use it in GitHub Desktop.
Save shm007g/6aad75db6c9fb30a1cacdd3befaf0e0d to your computer and use it in GitHub Desktop.

about git log

For the importance of commit-logs to committed-changes-review, logs are frequently checked. Effective and beautiful logs would double the efficiency. Then comes the question, how? One way is to making rules. Rules and convention makes logs lawful. The other way is to making the style. Beautiful styles makes logs delightful.

Convention

Angualr Convension is a popular and proper convention for this job. It regularizes logs with 'type-scope-msg' convention. Just like those below. Click-here-to-see-detail

Format

git log gives format-parameters to show what message you want to see in style you want.

  • Cmd behind is a popular log cmd:

git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --graph It shows logs like this:

It shows commit-hash-code, branch-position, commit-head, relative-commit-time, commit-author. This cmd fulfills most logs checking situation.

  • Then you may want to do this faster.

Here**!** Use this cmd below. git config --global alias.lg "log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(blue)<%an>%Creset' --abbrev-commit --graph" Config it into your global-git-configuration and make it happens for all git project on your current usr account. Then check it with git lg:

You may see this configuration though this cat ~/.gitconfig. Technically, you can just edit this file and make it happens.


about git config

You may have more than one git account(one for github and one for work), then you need use different account on different push and pull. You can config your .bash_profile for a faster account switching here:

  • firstly, make sure you've got one ssh keypair, and work properly well communicating with remote git code server.
  • secondly, you generate a new ssh keypair with new user.email using ssh-keygen and save this key with different file. Then you've got a second key/user to communicate with git server.
  • sh-add -l to list keys you local ssh client keeping. If your new key not in this client, just ssh-add $secret-key to add it.
  • third, you add this new pub-key to the github/gitlab settings. Then remote git server know your new key/user. you can clone code with authority.
  • Fouth, config what user you want to use to git pull/push on each project. There are two file doing this job, global ~/.gitconfig and local .git.config. I suggest you use your work user as global, which you put it in global file; and side project using this new user, which you can put it in project local .git/config file. you can do it quicker and add to bash alias.
    • alias gitme='git config user.name "Szymon"; git config user.email shm7@outlook.com' to config your own github account on this git project(Seeing ./.git/configfile for more info.)
    • alias gitwork='git config --global user.name "$workname"; git config --global user.email $workmail' to config your work account on this project(Seeing ~/.gitconfig file for more info.)

😀Now you can just use gitme and gitwork to switch account. And you can check it in ~/.gitconfig.

  • git config - Get and set repository or global options
  • git config --global core.editor vim set default editor
  • git config $key $value set config
  • git config $key get config
  • git config --list show all config in $key=$value list
  • git help <verb> , git <verb> --help or man git-<verb> show static text help

使用shadowsocks代理git,可以实现git clone十倍加速。

git config --global http.proxy 'socks5://127.0.0.1:1086' # 以实际端口为准,mac默认是1086
git config --global https.proxy 'socks5://127.0.0.1:1086'  # 以实际端口为准,mac默认是1086
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment