簡體   English   中英

重新構建Git倉庫基礎的Bash腳本

[英]Bash script that rebase Git repository

我正在嘗試找到一種使用Bash腳本對存儲庫進行基礎設置的方法,我明白了,但是它返回了很多我不知道如何解決的錯誤,例如: ./bash.sh: line 3: $'\\r': command not found

錯誤:

./bash.sh: line 3: $'\r': command not found
./bash.sh: line 6: $'\r': command not found
Updating Repo: /home/teste/ with url:
./bash.sh: line 8: $'\r': command not found
./bash.sh: line 16: syntax error near unexpected token `$'\r''
'/bash.sh: line 16: `(git fetch --all && git stash)

這是我得到的腳本

directory="/home/teste/" ## Where the server is located
original_dir="/root" ## Where we should back after the pull

cd $directory # switch to the git repo
repo_url=$(git config --get remote.origin.url)

echo "Updating Repo: $directory with url: $repo_url"

main_branch="master"
if [ "$repo_url" == "XXXXX" ]; then # if you have a repo where the primary branch isnt master
    $main_branch="trunk"
fi

# update the repo, then stash any local changes
echo -e "\ncalling: git fetch --all && git stash"
(git fetch --all && git stash)
current_branch=$(git rev-parse --abbrev-ref HEAD)

# switch to master/trunk branch and rebase it, then switch back to original branch
if [ $current_branch != $main_branch ]; then
    echo -e "\ncalling: git checkout $main_branch && git rebase && git checkout $current_branch"
    (git checkout $main_branch && git rebase && git checkout $current_branch)
fi

# rebase the original branch and then stash pop back to original state
echo -e "\ncalling: git rebase && git stash pop on branch: $current_branch"
(git rebase && git stash pop )

#switch back to the starting directory
cd $original_dir
echo ""

這是您的文件編碼,而不是腳本本身-Windows回車符不同於UNIX格式。 如果您使用的是GUI編輯器,請根據您的操作系統將行尾更改為“ unix”或“ win”格式。

還有一個名為dos2unix的工具,您可以針對一個文件運行該工具,以將行尾轉換為unix格式(反之亦然,unix2dos反之亦然)。

在您的.gitattributes配置中,您還可以設置所需的格式。 這樣可以確保您簽出並提交的代碼將來會得到相應處理:

text eol=crlf # unix

要么

text eol=lf # windows

參見: https : //help.github.com/articles/dealing-with-line-endings/

參見此頁面以其他方式給這只貓蒙皮。 '\\ r':找不到命令-.bashrc / .bash_profile

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM