2017-09-27 127 views
0

我試圖找到一種方法,通過使用bash腳本變基庫,我得到了這一點,但它返回了很多了一些錯誤,我不知道如何解決這些問題,例如:./bash.sh: line 3: $'\r': command not foundbash腳本的Git倉庫

錯誤:

./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 "" 
+0

首先,你沒有變基一個倉庫,你變基的一個分支。但是,除此之外,重新定位可能是一個非常複雜的過程,合併衝突可能並且經常發生。你打算如何處理來自bash腳本的合併衝突? –

回答

1

這是你的文件的編碼,而不是腳本本身的腳本 - 窗口回車是聯合國不同ix格式。如果您使用的是圖形用戶界面編輯器,改變你的行結束符爲「UNIX」或根據您的操作系統「雙贏」的格式。

還有一個名爲DOS2UNIX的,您可以運行對一個文件行結束轉換爲UNIX格式(或反之亦然unix2dos)工具。

在你.gitattributes配置你也可以設置你想要的格式。這將確保你檢查和提交的代碼獲得在未來相應處理:

text eol=crlf # unix 

OR

text eol=lf # windows 

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

看到這個頁面的其他方法對皮膚這隻貓。 '\r': command not found - .bashrc/.bash_profile

+1

謝謝!這是問題! – vankk