git 知识总结

 

一、添加文件到Git仓库,分两步:
1.第一步,使用命令git add <file>,注意,可反复多次使用,添加多个文件;
2.第二步,使用命令git commit,完成。
二、要随时掌握工作区的状态,使用git status命令。
如果git status告诉你有文件被修改过,用git diff可以查看修改内容。
三、时光穿梭
1.HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id
2.穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本。
3.要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。
四、Git跟踪并管理的是修改,而非文件
1.git diff HEAD a.txt   查看文件的修改   git diff HEAD~3  ; git diff  <版本号,前6位>
2.
五.撤销修改
1.git checkout — a.txt
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commitgit add时的状态。
备注:也就是说,用了checkout —  命令后 , 编辑,git add后编辑或者git commit后编辑后的内容,将失效,回到前一次操作的状态
2.用命令git reset HEAD file可以把暂存区的修改撤销掉(unstage)
3.git reset命令既可以回退版本,也可以把暂存区的修改回退到工作区。当我们用HEAD时,表示最新的版本。
4.丢弃工作区的修改  git checkout   a.txt
git reset HEAD a.txt    只是把暂存区的文件取出来,不会修改文件  commit 后,就不行了commit  后就用时光机吧
5.当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file
6.当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,就回到了场景1,第二步按场景1操作。
六、git reset 回退某一个版本  git revert  回退某一个版本生成一个新的commit
七、穿件分支和合并分支
1.查看分支:git branch
2.创建分支:git branch <name>
3.切换分支:git checkout <name>
4.创建+切换分支:git checkout -b <name>
5.合并某分支到当前分支:git merge <name>
6.删除分支:git branch -d <name>
八、解决冲突
1.当Git无法自动合并分支时,就必须首先解决冲突。解决冲突后,再提交,合并完成。
2.git log --graph  查看分支合并图
3.git 可以帮你合并一些简单,当修改的同一个地方,无法解决的时候,就需要手动解决冲突问题了
九、bug修复
1.stash功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作;
2.git stash list命令看看stash记录
3.git stash apply 或者多个stash  用git stash apply stash@{1} 来恢复
4.stash用git stash drop来删除;git stash pop,恢复的同时把stash内容也删了;
十、小技巧
1.开发一个新feature,最好新建一个分支;
2.如果要丢弃一个没有被合并过的分支,可以通过git branch -D <name>强行删除。
十一、多人协作
1.首先,可以试图用git push origin branch-name推送自己的修改;
2.如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并;
3.如果合并有冲突,则解决冲突,并在本地提交;
4.没有冲突或者解决掉冲突后,再用git push origin branch-name推送就能成功!
5.如果git pull提示“no tracking information”,则说明本地分支和远程分支的链接关系没有创建,用命令git branch --set-upstream branch-name origin/branch-name
备注:1.查看远程库信息,使用git remote -v
2.本地新建的分支如果不推送到远程,对其他人就是不可见的;
3.从本地推送分支,使用git push origin branch-name,如果推送失败,先用git pull抓取远程的新提交;
4.在本地创建和远程分支对应的分支,使用git checkout -b branch-name origin/branch-name,本地和远程分支的名称最好一致;
5.建立本地分支和远程分支的关联,使用git branch --set-upstream branch-name origin/branch-name
6.从远程抓取分支,使用git pull,如果有冲突,要先处理冲突。
十二、标签
1.命令git tag <name>用于新建一个标签,默认为HEAD,也可以指定一个commit id;
2.git tag -a <tagname> -m "blablabla..."可以指定标签信息;
3.git tag -s <tagname> -m "blablabla..."可以用PGP签名标签;
4.命令git tag可以查看所有标签。
5.git show <tagname>  查看标签的详细信息
操作标签:
1.命令git push origin <tagname>可以推送一个本地标签;
2.命令git push origin --tags可以推送全部未推送过的本地标签;
3.命令git tag -d <tagname>可以删除一个本地标签;
4.命令git push origin :refs/tags/<tagname>可以删除一个远程标签。
十三、忽略文件
1.忽略某些文件时,需要编写.gitignore
2.gitignore文件本身要放到版本库里,并且可以对.gitignore做版本管理!
3.所有配置文件可以直接在线浏览:https://github.com/github/gitignore
备注:对已经进入版本库的文件无效,除非删除版本库的内容,才能起作用
十四、配置别名
1.git st就表示git status   配置git config --global alias.st status  其他的类似
2.git checkout   :git config --global alias.co checkout
3.查看配置 git config --list 本地仓库;git config --global --list  查看全局的仓库配置
4.git last 查看最后一条commit
5.

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

 

总结一些比较好用的指令
1.谁动了我的奶酪   git blame a.txt
2.git log  –onelime  –graph     显示log
3.git reflog 列出历史操作的log;  git fsck --lost-found 这个更厉害
4.git grep  搜索内容

更多详细指令介绍参看链接:http://blog.xiaofangmoon.com/?p=21

php-fpm 启动关闭

编辑php-fpm.conf,把pid文件注释去掉,这里加了注释并不是默认值,而是不生成pid文件。
启动,php-fpm
关闭:kill -INT `cat /home/server/php-5.4.15/var/run/php-fpm.pid`
重启:kill -USR2 `cat /home/server/php-5.4.15/var/run/php-fpm.pid`

 linux中查找命令find、locate、whereis、which、type区别

1.find
find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件。与查询数据库(/var/lib/locatedb)文件不同,find查找磁盘空间

find的使用格式如下:

$ find <指定目录> <指定条件> <指定动作>

– <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。

– <指定条件>: 所要搜索的文件的特征。

– <指定动作>: 对搜索结果进行特定的处理。

如果什么参数也不加,find默认搜索当前目录及其子目录,并且不过滤任何结果(也就是返回所有文件),将它们全都显示在屏幕上。

find的使用实例:

$ find . -name ‘my*’

搜索当前目录(含子目录,以下同)中,所有文件名以my开头的文件。

$ find . -name ‘my*’ -ls

搜索当前目录中,所有文件名以my开头的文件,并显示它们的详细信息。

$ find . -type f -mmin -10

搜索当前目录中,所有过去10分钟中更新过的普通文件。如果不加-type f参数,则搜索普通文件+特殊文件+目录。

2. locate

Java代码

locate命令其实是”find -name”的另一种写法,但是要比后者快得多,原因在于它不搜索具体目录,而是搜索一个数据库(/var/lib/locatedb),这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。

locate命令的使用实例:

$ locate /etc/sh

搜索etc目录下所有以sh开头的文件。

$ locate ~/m

搜索用户主目录下,所有以m开头的文件。

$ locate -i ~/m

搜索用户主目录下,所有以m开头的文件,并且忽略大小写。

3. whereis

Java代码

whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b)、man说明文件(参数-m)和源代码文件(参数-s)。如果省略参数,则返回所有信息。同locate一样,查询数据库(/var/lib/locatedb)文件

whereis命令的使用实例:

$ whereis grep

4. which

Java代码

which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。

which命令的使用实例:

$ which grep

5. type

Java代码

type命令其实不能算查找命令,它是用来区分某个命令到底是由shell自带的,还是由shell外部的独立二进制文件提供的。如果一个命令是外部命令,那么使用-p参数,会显示该命令的路径,相当于which命令。

type命令的使用实例:

$ type cd

系统会提示,cd是shell的自带命令(build-in)。

$ type grep

系统会提示,grep是一个外部命令,并显示该命令的路径。

$ type -p grep

加上-p参数后,就相当于which命令

mac 下php多版本切换

安装php-version及其简单实用

php-version是一个帮助管理从brew安装的php版本切换的工具。
安装简单

$brew install php-version

然后执行

$source $(brew --prefix php-version)/php-version.sh && php-version 5

直接执行
php-version
就可以看到现有的版本,比如我自己的

$ php-version
* 5.6.4
    5.6.5

然后使用以下命令切换即可

$php-version 5.6.5

再看php的版本,已经切换好了。

apache rewrite 详解

核心摘要:用rewrite可实现的部分:URL根目录搬迁,多目录查找资源,阻止盗连你的图片,拒绝某些主机访问,基于时间重写,据浏览器类型重写,动态镜像远程资源,外部重写程序模板,等等详见下表:目标重写…

用rewrite可实现的部分:URL根目录搬迁,多目录查找资源,阻止盗连你的图片,拒绝某些主机访问,基于时间重写,据浏览器类型重写,动态镜像远程资源,外部重写程序模板,等等

详见下表:

目标 重写设置 说明
规范化URL RewriteRule ^/~([^/]+)/?(.*) /u/$1/$2 [R] 将/~user重写为/u/user的形式
RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R] 将/u/user末尾漏掉的/补上
规范化HostName RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] 域名不合格
RewriteCond %{HTTP_HOST} !^$ 不空
RewriteCond %{SERVER_PORT} !^80$ 不是80端口
RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R] 重写
RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]
URL根目录转移 RewriteEngine on
RewriteRule ^/$ /e/www/ [R] 从/移到/e/www/
末尾目录补斜线 RewriteEngine on
(目录范围内) RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R] /~quux/foo是一个目录,补/
RewriteEngine on
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d 如果请文件名是个目录
RewriteRule ^(.+[^/])$ $1/ [R] URL末尾不是斜线时补上
Web集群 RewriteEngine on
RewriteMap user-to-host txt:/path/to/map.user-to-host 用户-服务器映射
RewriteMap group-to-host txt:/path/to/map.group-to-host 组-服务器映射
RewriteMap entity-to-host txt:/path/to/map.entity-to-host 实体-服务器映射
RewriteRule ^/u/([^/]+)/?(.*) http://${user-to-host:$1|server0}/u/$1/$2 用户均衡
RewriteRule ^/g/([^/]+)/?(.*) http://${group-to-host:$1|server0}/g/$1/$2 组均衡
RewriteRule ^/e/([^/]+)/?(.*) http://${entity-to-host:$1|server0}/e/$1/$2 实体均衡
RewriteRule ^/([uge])/([^/]+)/?$ /$1/$2/.www/
RewriteRule ^/([uge])/([^/]+)/([^.]+.+) /$1/$2/.www/$3\
URL根目录搬迁 RewriteEngine on
RewriteRule ^/~(.+) http://newserver/~$1 [R,L] 到其它服务器
所用户名首字母分 RewriteEngine on
RewriteRule ^/~(([a-z])[a-z0-9]+)(.*) /home/$2/$1/.www$3 内一层括号为$2
NCSA imagemap移 RewriteEngine on
植为mod_imap RewriteRule ^/cgi-bin/imagemap(.*) $1 [PT]
多目录查找资源 RewriteEngine on
# first try to find it in custom/…
RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir1/$1 [L]
# second try to find it in pub/…
RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir2/$1 [L]
# else go on for other Alias or Alias directives,
RewriteRule ^(.+) – [PT]
据URL设置环境变量 RewriteEngine on
RewriteRule ^(.*)/S=([^/]+)/(.*) $1/$3 [E=STATUS:$2]
虚拟主机 RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$ 基于用户名
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
内外人有别 RewriteEngine on
RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$ 基于远程主机
RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]
错误重定向 RewriteEngine on
RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f 不是regular文件
RewriteRule ^(.+) http://webserverB.dom/$1
程序处理特殊协议 RewriteRule ^xredirect:(.+) /path/to/nph-xredirect.cgi/$1 \ Xredirect协议
[T=application/x-httpd-cgi,L]
最近镜像下载 RewriteEngine on
RewriteMap multiplex txt:/path/to/map.cxan 顶级域名与最近ftp服务器映射
RewriteRule ^/CxAN/(.*) %{REMOTE_HOST}::$1 [C]
RewriteRule ^.+\.([a-zA-Z]+)::(.*)$ ${multiplex:$1|ftp.default.dom}$2 [R,L] 据顶级域名不同提供不同的FTP服务器
基于时间重写 RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0700
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule ^foo\.html$ foo.day.html 白天为早晚7点间
RewriteRule ^foo\.html$ foo.night.html 其余为夜间
向前兼容扩展名 RewriteEngine on
RewriteBase /~quux/
# parse out basename, but remember the fact
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
# rewrite to phtml if exists
RewriteCond %{REQUEST_FILENAME}.phtml -f 如果存在$1.phtml则重写
RewriteRule ^(.*)$ $1.phtml [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$ 如果不存在$1.phtml,则保持不变
RewriteRule ^(.*)$ $1.html
文件改名(目录级) RewriteEngine on 内部重写
RewriteBase /~quux/
RewriteRule ^foo\.html$ bar.html
RewriteEngine on 重定向由客户端再次提交
RewriteBase /~quux/
RewriteRule ^foo\.html$ bar.html [R]
据浏览器类型重写 RewriteCond %{HTTP_USER_AGENT} ^Mozilla/3.*
RewriteRule ^foo\.html$ foo.NS.html [L]
RewriteCond %{HTTP_USER_AGENT} ^Lynx/.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].*
RewriteRule ^foo\.html$ foo.20.html [L]
RewriteRule ^foo\.html$ foo.32.html [L]
动态镜像远程资源 RewriteEngine on
RewriteBase /~quux/
RewriteRule ^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1 [P] 利用了代理模块
RewriteEngine on
RewriteBase /~quux/
RewriteRule ^usa-news\.html$ http://www.quux-corp.com/news/index.html [P]
反向动态镜像 RewriteEngine on
RewriteCond /mirror/of/remotesite/$1 -U
RewriteRule ^http://www\.remotesite\.com/(.*)$ /mirror/of/remotesite/$1
负载均衡 RewriteEngine on 利用代理实现round-robin效果
RewriteMap lb prg:/path/to/lb.pl
RewriteRule ^/(.+)$ ${lb:$1} [P,L]
#!/path/to/perl
$| = 1;
$name = “www”; # the hostname base
$first = 1; # the first server (not 0 here, because 0 is myself)
$last = 5; # the last server in the round-robin
$domain = “foo.dom”; # the domainname
$cnt = 0;
while (<STDIN>) {
$cnt = (($cnt+1) % ($last+1-$first));
$server = sprintf(“%s%d.%s”, $name, $cnt+$first, $domain);
print “http://$server/$_”;
}
##EOF##
静态页面变脚本 RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo\.html$ foo.cgi [T=application/x-httpd-cgi]
阻击机器人 RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$
RewriteRule ^/~quux/foo/arc/.+ – [F]
阻止盗连你的图片 RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC] 自己的连接可不能被阻止
RewriteRule .*\.gif$ – [F]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$
RewriteRule ^inlined-in-foo\.gif$ – [F]
拒绝某些主机访问 RewriteEngine on
RewriteMap hosts-deny txt:/path/to/hosts.deny
RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^/.* – [F]
用户授权 RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend1@client1.quux-corp\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend2@client2.quux-corp\.com$
RewriteCond %{REMOTE_IDENT}@%{REMOTE_HOST} !^friend3@client3.quux-corp\.com$
RewriteRule ^/~quux/only-for-friends/ – [F]
外部重写程序模板 RewriteEngine on
RewriteMap quux-map prg:/path/to/map.quux.pl
RewriteRule ^/~quux/(.*)$ /~quux/${quux-map:$1}
#!/path/to/perl
$| = 1;
while (<>) {
s|^foo/|bar/|;
print $_;
}
搜索引擎友好 RewriteRule ^/products$ /content.php
RewriteRule ^/products/([0-9]+)$ /content.php?id=$1
RewriteRule ^/products/([0-9]+),([ad]*),([0-9]{0,3}),([0-9]*),([0-9]*$) /marso/content.php?id=$1&sort=$2&order=$3&start=$4

相关文章:

1、如何在Apache环境下配置Rewrite规则
http://www.onexin.net/how-to-configure-rewrite-rules-apache-environment/

2、在Mac OS X Yosemite下搭建Apache+PHP+Mysql
http://www.onexin.net/build-in-mac-os-x-yosemite-apachephpmysql/

3、Apache错误日志[warn] child process * still did not exit, sending a SIGTERM解决办法
http://www.onexin.net/the-apache-error-log-warn-child-process-still-did-not-exit-sending-a-sigterm-solutions/

4、Apache安全和强化的十三个技巧
http://www.onexin.net/apache-security-and-strengthen-the-thirteen-skills/

 

原文地址:http://www.onexin.net/apache-rewrite-detailed/

Apache的Directory配置指南

使用<Directory>… </Directory>设置指定目录的访问权限,其中可包含:
Options
AllowOverride
Order
Allow
Deny
五个属性。
Options属性
Options FollowSymLinks Indexes MultiViews
Options可以组合设置下列选项:
All:用户可以在此目录中作任何事情。
ExecCGI:允许在此目录中执行CGI程序。
FollowSymLinks:服务器可使用符号链接指向的文件或目录。
Indexes:服务器可生成此目录的文件列表。
None:不允许访问此目录。
AllowOverride
AllowOverride None
AllowOverride会根据设定的值决定是否读取目录中的.htaccess文件,来改变原来所设置的权限。
All:读取.htaccess文件的内容,修改原来的访问权限。
None:不读取.htaccess文件
为避免用户自行建立.htaccess文件修改访问权限,http.conf文件中默认设置每个目录为: AllowOverride None。
AccessFileName
AccessFileName filename
AccessFileName指令用于指定保护目录设定文件的文件名称,默认值为“.htaccess”。
AccessFileName .acl

Allow
设定允许访问Apache服务器的主机
Allow from all
允许所有主机的访问
Allow from 202.96.0.97 202.96.0.98
允许来自指定IP地址主机的访问

Deny 设定拒绝访问Apache服务器的主机 Deny from all 拒绝来自所有主机的访问 Deny from 202.96.0.99 202.96.0.88 拒绝指定IP地址主机的访问

Order Order allow,deny Order用于指定allow和deny的先后次序。

grunt 学习

一、工具安装
1.yeoman 安装 npm install -g yo
2.bower  安装 npm install -g bower
3.grunt 安装  npm install -g grunt
备注:三个是独立开发的,但要配合使用,完成一个自动化工作流

二、实践

1.建立一个简单的项目 yo webapp grunt-by-yo  项目名
2.执行其中一个task       grunt  sass:xiaofangsass
3.初始化一个项目
npm init  ;  //生成  package.json 文件
安装两个好用的模块:npm install load-grunt-tasks –save-dev      npm install  time-grunt –save-dev
4.npm install grunt-contrib-copy –save-dev 拷贝
npm install grunt-contrib-clean –save-dev  清除
4.执行单个任务  grunt  copy:dist_html
5.yo webapp grunt-yo-webapp  通过yoman 安装一个简单的webapp
启动一个server   ,grunt server  –allow-remote

发布自己的插件:
1.先要去https://www.npmjs.com/ 注册账号
2.npm  adduser
3.npm publish  <你的项目,git的的下载地址>
4.然后就可以到 https://www.npmjs.com 去搜索你的项目了
备注:1.npm install -g generator-gruntplugin    2.yo gruntplugin grunt-xiaofang(插件名字)