2019年8月

.gitignore忽略已提交的文件

对于首次提交时,会忽略.gitignore中对应的文件。如果已提交再次修改.gitignore则不会忽略,仍会追踪文件变化。

解决:
git rm --cached folder/file 并修改.gitignore文件

另:
git update-index --assume-unchanged 的真正用法是这样的:

  1. 你正在修改一个巨大的文件,你先对其 git update-index --assume-unchanged,这样 Git
    暂时不会理睬你对文件做的修改
  2. 当你的工作告一段落决定可以提交的时候,重置改标识:git update-index
    --no-assume-unchanged,于是 Git 只需要做一次更新,这是完全可以接受的了
  3. 提交+推送

原文:https://segmentfault.com/q/1010000000430426

shell判断文件、文件夹是否存在

dir="/folder"
file="/test/test.txt"
file2="/test/test.php"

判断文件夹是否存在,不存在则创建
if [ ! -d "${dir}" ]; then
    mkdir -p ${dir}
fi

判断文件是否存在且可执行
if [ ! -x "${dir}"]; then
    mkdir "${dir}"
fi

判断文件是否存在
if [ ! -f "$file" ]; then
    touch "$file"
fi

判断变量是否有值
if [ ! -n "$file" ]; then
 echo "$file 变量为空!"
 exit 0
fi

判断两个变量的字符串内容是否相同
if [ "$file" = "$file2" ]; then
    echo "$file equal $file2"
else
    echo "$file not equal $file2"
fi

shell脚本批量检测mysql表中是否存在指定字段

批量查询数据库中表是否存在指定字段,批量添加表字段:

#!/bin/bash
#exit
db_con="/usr/local/mysql/bin/mysql -uroot -p123456"
arr=(db1 db2 db3)
for db in ${arr[*]}
do
    ${db_con} -e "select count(*) from information_schema.columns where table_schema = '${db}' and table_name = 'table_name' and column_name = 'column_name';"  >> /data/shell/test.txt
    echo ${db} >> /data/shell/test.txt 
    #${db_con} -e "ALTER TABLE ${db}.gy_com_customer ADD new_column varchar(100) NOT NULL default '';" 2>/dev/null
    echo ${db} " --- done"
done