wsl文件最好不要在windows下编译

发布时间 2024-01-09 15:35:46作者: zyqcome

1 前提描述

  1. 我渐渐习惯使用 Win10 Linux Bash Shell,之前用过 Ubuntu 18
  2. 通过 Win10 bash,建立文件,在win10中,通过 notepad++ 编辑文件
  3. 通过 notepa++ 修改 ubuntu 下的编程文件,除了偶然会修改掉文件的权限,没有大的问题

2 问题

问题出在我打算实现一个 自动发布和提交的 .sh 文件的时候出了问题

  1. 通过 git 管理文档每次提交推送都会执行的三个命令
git add .
git commit -m "XXXX"
git push

我寻思着,每次都这样执行这三条,另外,hexo的每次编译,发布的命令也挺烦人

  1. 在 Ubuntu 下已经创建了一个 gitpush.sh ,回到 win10中,在 notepad++ 添加以下内容
time=$(date "+%Y%m%d-%H%M%S")
if [ -n "$time" ]; then
   git add -A
   git commit -m"${time}"
   git push
   git status
   echo "完成push"
else
   echo "请添加注释再来一遍"
fi

实现的功能是以时间戳作为 commit,提交和推送当前修改

在执行的时候遇到问题

XXX@XXX-x1:~/gitfile/blog$ sudo ./gitpush.sh
error: unknown option `all?'
usage: git add [<options>] [--] <pathspec>...

    -n, --dry-run         dry run
    -v, --verbose         be verbose

    -i, --interactive     interactive picking
    -p, --patch           select hunks interactively
    -e, --edit            edit current diff and apply
    -f, --force           allow adding otherwise ignored files
    -u, --update          update tracked files
    --renormalize         renormalize EOL of tracked files (implies -u)
    -N, --intent-to-add   record only the fact that the path will be added later
    -A, --all             add changes from all tracked and untracked files
    --ignore-removal      ignore paths removed in the working tree (same as --no-all)
    --refresh             don't add, only refresh the index
    --ignore-errors       just skip files which cannot be added because of errors
    --ignore-missing      check if - even missing - files are ignored in dry run
    --chmod <(+/-)x>      override the executable bit of the listed files

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
        modified:   README.md
        modified:   themes/sky (modified content)

Untracked files:
        gitpush.sh

no changes added to commit
' is not a git command. See 'git --help'.

The most similar command is
        push
' is not a git command. See 'git --help'.

The most similar command is

遇到这个问题我一开始的方向是以为 shell 命令没有写对,找了好一通的各种写法尝试

3 尾声

解决掉这个问题后其他的就很顺利,从体验上来说,有了 shell 确实让人更舒服了

4 两个sh的实现

  • gitpush.sh git 的shell 提交
time=$(date "+%Y%m%d-%H%M%S")
if [ -n "$time" ]; then
   git add -A
   git commit -m"${time}"
   git push
   git status
   echo "完成push"
else
   echo "请添加注释再来一遍"
fi
  • hexo 的编译和 ftp 发布
sh gitpush.sh #先执行git提交
hexo generate
hexo deploy
  • 在编辑完此文后,可以执行下面的命令来完成 备份和发布了
./release.sh