2016年12月12日星期一

Git批量添加文件的三种方法及其区别(Stack Overflow转载)

git add -A is equivalent to git add .; git add -u.
The important point about git add . is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.
git add -u looks at all the already tracked files and stages the changes to those files if they are different or if they have been removed. It does not add any new files, it only stages changes to already tracked files.
git add -A is a handy shortcut for doing both of those.
You can test the differences out with something like this (note that for Git version 2.x your output for git add . git status will be different):
git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial

echo OK >> change-me
rm delete-me
echo Add me > add-me

git status
# Changed but not updated:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git add .
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
# Changed but not updated:
#   deleted:    delete-me

git reset

git add -u
git status

# Changes to be committed:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git reset

git add -A
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
#   deleted:    delete-me
Summary:
  • git add -A stages All
  • git add . stages new and modified, without deleted
  • git add -u stages modified and deleted, without new

2016年12月7日星期三

PHP判断字符串包含的文字类型

不多说,直接上代码。


补充知识点: 正则式后面的u表示模式字符串将被以UTF-8字符模式对待。在匹配中文的时候必须带上,只有这样才能正确匹配中文字符。

js的encodeURI()函数

在使用JavaScript向PHP传值的时候,一定要记得要进行预处理。也就是使用encodeURI()函数。今天就因为这个浪费了很多时间查错,小记一下作为警示。

2016年12月5日星期一

PHP如何动态地获取文件的扩展名

如题,今天在做brandpronounce这个项目的时候需要把down到的图片和brand结合起来,但是图片扩展名各不相同,导致无法一起使用相同的后缀链接,要转换图片格式又嫌麻烦,在尝试了很多种方法都无果之后,采用了以下效率比较低的方案。

首先使用scandir()函数把imgs文件夹下的图片罗列出来,放在一个foreach()循环中,使用pathinfo()把每次取得的文件名和brand名进行比对,如果一致就返回这个文件名。

值得一提的是pathinfo()的第二个参数指定了返回什么内容,PATHINFO_BASENAME是返回带后缀名的完整文件名,而PATHINFO_FILENAME则是返回不带后缀名的版本。


2016年12月2日星期五