Blog

  • 做一次 git 完美提交

    分离主题和内容
    主题控制在 50 个字符
    主题第一个字母大写
    主题行不要用句号结束
    主题行使用祈使语气
    内容每 72 个字符换行
    在内容里解释改变的大致内容 what 和原因 why (改变的方式 how 在 git diff 里可以看到,不用说)

    http://chris.beams.io/posts/git-commit/

  • ansible批量添加用户

    有用的 snippet

    ansible all  -l 'web' -m user -a "name=www shell=/bin/bash createhome=yes"
  • 局域网内一台机器用做网关

    虚拟机:192.168.1.111

    安装 pptp-setup

    yum install pptp-setup

    创建 pptp

    pptpsetup --create p1_jp1 --server p1.jp1.jpuyy.com --username user --password pass --start

    这之后会有文件 /etc/ppp/peers/p1_jp1

    # written by pptpsetup
    pty "pptp p1.jp1.jpuyy.com --nolaunchpppd"
    lock
    noauth
    nobsdcomp
    nodeflate
    name user
    remotename p1_jp1
    ipparam p1_jp1
    require-mppe
    

    对应的密码文件记录在 /etc/ppp/chap-secrets

    之后要想连接或断开 pptp,可以使用,做两个软链

    ln -s /usr/share/doc/ppp-2.4.5/scripts/pon /usr/local/bin/
    ln -s /usr/share/doc/ppp-2.4.5/scripts/poff /usr/local/bin/
    

    之后运行

    pon p1_jp1

    如果发现连不上,还需要启用 ip_gre 模块。参见这里

    打开 ip 转发

    更改 /etc/sysctl.conf

    net.ipv4.ip_forward = 1

    sysctl -p 生效

    设置 nat

    -A POSTROUTING -o ppp0 -j MASQUERADE

    替换默认网关

    ip route replace default dev ppp0

    至此,局域网中的其他机器可以设置把 192.168.1.111 做为网关了。

  • git diff 高亮显示改变的单词

    平时 git diff 都是以行级别的

    如果以单词级别的可以这样

    git diff --color-words
    git diff --word-diff
  • git cherry pick 任意选 commit merge 过来

    在 git 里,每一个 commit 都带有一个 sha1 的标识,在任何分支,任何状态下,如果你知道这次提交的相关情况,可以将一次 commit merge 过来。

    git cherry-pick 2379df
  • git 压缩提交 squash merge

    分支里多次提交合并成一个提交

    示例

    将最近几个(number_of_commits) 提交合并成一个提交

    git rebase -i HEAD~[number_of_commits]

    然后进入交互式选择

    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    #
    # These lines can be re-ordered; they are executed from top to bottom. #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out
    
    

    这里先进行 commit 方面的选择,把除去第一行的都改为 squash

    pick f7f3f6d changed my name a bit
    squash 310154e updated README formatting and added blame
    squash a5f4a0d added cat-file
    

    然后进行 commit msg 的界面,自己写一下合并后的 commit。

    分支的 push 强制提交会将本地操作生效

    参考:

    pro git