在 git 里,每一个 commit 都带有一个 sha1 的标识,在任何分支,任何状态下,如果你知道这次提交的相关情况,可以将一次 commit merge 过来。
git cherry-pick 2379df
在 git 里,每一个 commit 都带有一个 sha1 的标识,在任何分支,任何状态下,如果你知道这次提交的相关情况,可以将一次 commit merge 过来。
git cherry-pick 2379df
分支里多次提交合并成一个提交
示例
将最近几个(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
经常 commit –amend,merge,rebase,reset –hard 后,会产生一些没有引用的 objects,这些有的可能会恢复你误操作后的修改,但是大部分时间是没用的。想着清理一下。
先查看有哪些
git fsck --full
然后查看已经没有的引用
git reflog expire --expire=now --all
清理
git gc --prune=now
参考:
http://www.tekkie.ro/news/howto-remove-all-dangling-commits-from-your-git-repository/
查看远端( origin ) 的时候,发现有些分支已经 stale 了
git remote show origin
stale (use 'git remote prune' to remove)
修剪
git remote prune origin
场景:
如果源站文件有更新,则重新下载。如果没有更新,则不下载。全部是根据 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
如果用户的 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;
}