Created
July 21, 2016 12:17
-
-
Save RickieL/8935bc1f5bae0baaea0cedbf0b1d5162 to your computer and use it in GitHub Desktop.
commit the file that rm by none git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 环境 CentOS 7.2 | |
# 统一语言环境,方便后面的匹配 | |
export LANG=en_US.UTF-8 | |
# 标记个时间吧^_^ | |
DateTime=$(date +"%F %T") | |
Timestamp=$(date +"%s") | |
# 到对应项目的根目录 | |
Src=$1 | |
if [ -d $Src ] ; then | |
cd $Src | |
else | |
echo "there is no such dir: $Src " | |
exit 1 | |
fi | |
# 先将所有其他的修改提交到暂存区 | |
git add * | |
# 将所有永福删除的文件提交到暂存区 | |
git status |sed -n '/Changes not staged for commit/,$p' |grep 'deleted:' > /tmp/git-rm-$Timestamp.log | |
Num=$(wc -l /tmp/git-rm-$Timestamp.log |awk '{print $1}') | |
if [ $Num -ge 1 ]; then | |
cat /tmp/git-rm-$Timestamp.log |awk '{ $1=""; $2=""; print $0}' |sed -e 's/^[ \t]*//g' -e 's/[ \t]*$//g' |xargs -i echo '"{}"' | xargs git rm | |
fi | |
# 提交所有修改(包括删除的文件) | |
git commit -m "$DateTime : 备份了版本库" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment