Author: jpuyy

  • 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

  • git fsck 清理 dangle objects

    经常 commit –amend,merge,rebase,reset –hard 后,会产生一些没有引用的 objects,这些有的可能会恢复你误操作后的修改,但是大部分时间是没用的。想着清理一下。

    先查看有哪些

    git fsck --full

    Dangling blob = A change that made it to the staging area/index, but never got committed. One thing that is amazing with Git is that once it gets added to the staging area, you can always get it back because these blobs behave like commits in that they have a hash too!!

    Dangling commit = A commit that isn’t directly linked to by any child commit, branch, tag or other reference. You can get these back too!

    Dangling tree

    然后查看已经没有的引用

    git reflog expire --expire=now --all

    git reflog: record when refs were update in the local repository, useful for recovering lost commits

    清理

    git gc --prune=now

    git gc: clean up and optimize the local repository

    参考:
    http://www.tekkie.ro/news/howto-remove-all-dangling-commits-from-your-git-repository/
    https://git-scm.com/docs/git-fsck
    https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery

  • git 远端分支修剪 prune

    查看远端( origin ) 的时候,发现有些分支已经 stale 了

     git remote show origin 
     stale (use 'git remote prune' to remove)

    修剪

    git remote prune origin
  • curl wget判断一个文件是不是足够新去下载

    场景:

    如果源站文件有更新,则重新下载。如果没有更新,则不下载。全部是根据 Last-Modified 来判断。

    http://blog.yjl.im/2012/03/downloading-only-when-modified-using.html
    http://blog.yjl.im/2012/03/downloading-only-when-modified-using_23.html

  • nginx判断cookie 和 user-agent 跳转到 pc 或 m 站

    如果用户的 cookie 中已经访问过 m 站,或使用手机端的时候,跳转到手机端

            if ($cookie_mobile = "1") {
                rewrite ^ http://m.example.com/ redirect;
            }
            if ($http_user_agent ~* "android|iphone|ipod|windows\sphone") {
                rewrite ^ http://m.example.com/ redirect;
            }
    
  • centos7 图形界面和字符界面切换

    通过 systemctl 控制

    1. 字符界面

    systemctl set-default multi-user.target

    2. 图形界面

    systemctl set-default graphical.target