Blog

  • 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
  • 将 bitbucket 迁移到 github

    先装 bitbucket 中的 origin 命名成 bitbucket

    git remote rename origin bitbucket

    在 github 添加 origin

    git remote add origin https://github.com/username/myproject.git

    将 master 发上去

    git push origin master

    将 bitbucket 删掉

    git remote rm bitbucket

    在这里操作可以查看 .git/config 中的变化

    http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/