2017-09-27 1 views
0

Ich versuche, einen Weg zu finden, das Repository mit einem Bash-Skript zu rebasen, ich habe das, aber es gab viele Fehler, die ich nicht, wie Sie sie zum Beispiel beheben können : ./bash.sh: line 3: $'\r': command not foundBash-Skript, das Git-Repository neu erstellen

Fehler:

./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) 

Hier ist das Skript, das ich

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

Zunächst einmal, Sie nicht ein Repository neu, Sie Rebase eine Filiale. Abgesehen davon kann Rebasing ein sehr komplizierter Prozess sein, und Konflikte können und werden häufig auftreten. Wie wollen Sie mit Konflikten aus einem Bash-Skript umgehen? –

Antwort

1

bekam Es ist Ihre Datei-Codierung, nicht das Scripting selbst - Fenster Zeilenumbrüche zu un verschieden sind ix Format. Wenn Sie einen GUI-Editor verwenden, ändern Sie die Zeilenenden abhängig vom Betriebssystem in das Unix- oder das Win-Format.

Es gibt auch ein Tool namens dos2unix, das Sie gegen eine Datei ausführen können, um Zeilenenden in Unix-Format zu konvertieren (oder umgekehrt unix2dos).

In Ihrer .gitattributes-Konfiguration können Sie auch das gewünschte Format festlegen. Dies wird sicherstellen, dass der Code, den Sie überprüfen und sich verpflichten wird entsprechend in der Zukunft behandelt:

text eol=crlf # unix 

ODER

text eol=lf # windows 

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

Siehe diese Seite für andere Möglichkeiten, um die Haut diese Katze . '\r': command not found - .bashrc/.bash_profile

+1

Danke! Das war das Problem! – vankk