2011-12-13 17 views
20

मैं एक निर्देशिका में सभी फ़ाइलों को जोड़ने, प्रतिबद्ध करने, धक्का देने के लिए एक बैश स्क्रिप्ट लिख रहा हूं।गिट प्रतिबद्ध बैश स्क्रिप्ट

#!/bin/bash 
git add . 
read -p "Commit description: " desc 
git commit -m $desc 
git push origin master 

मैं निम्न त्रुटि हो रही है:

$ ./togithub 
Commit description: 
test commit script 
error: pathspec 'commit' did not match any file(s) known to git. 
error: pathspec 'script"' did not match any file(s) known to git. 
Everything up-to-date 

मुझे यकीन है कि नहीं कर रहा हूँ अगर यह पाठ में पढ़ने के साथ एक समस्या है (यह echo रों ठीक) है या git commit -m को इसे पारित।

git commit -m "$desc" 

वर्तमान स्क्रिप्ट में, test के रूप में जा रहा है संदेश और commit और script अगले तर्क के रूप में इलाज किया जा रहा है के लिए प्रतिबद्ध:

उत्तर

29

आप क्या करना है।

+1

"उचित उद्धरण करें" को कभी भी अतिरंजित नहीं किया जा सकता है। नेट पर बहुत सारे उपपर "हाउटोस" और अर्ध-सही सलाह/उदाहरण ... –

4

यह वास्तव में हटाई गई फ़ाइलों को इंडेक्स से निकालने में मददगार है। git add -u इसका ख्याल रखता है। इसके अलावा, आप इस तरह एक साथ इन आदेशों चेनिंग विचार कर सकते हैं: किसी भी आदेश विफल रहता है

git add . && \ 
git add -u && \ 
git commit -m "$(read -p 'Commit description: ')" && \ 
git push origin HEAD 

है, यह शेष आदेशों का मूल्यांकन करना बंद कर देगा।

विचार के लिए बस भोजन (अनचाहे भोजन)।

धन्यवाद!

+2

यदि कोई आदेश विफल हो जाता है तो आप स्क्रिप्ट से बाहर निकलने के लिए '#!/Bin/bash -e' का भी उपयोग कर सकते हैं। – bluegray

+0

मजेदार है कि यह बहुत अधिक हो गया है ... आपको खाली प्रतिबद्ध संदेश मिलेंगे ... –

8

यहां पिछले दो उत्तरों का विलय है - add -u को एक साथ जोड़ना बहुत ही बढ़िया है, लेकिन एम्बेडेड रीड कमांड मुझे परेशान कर रहा था। मैं (पिछले मेरी Heroku धक्का के लिए इस्तेमाल किया लाइन, 'Git धक्का मूल सिर' के लिए बदल कि अगर आपके विधि है) के साथ चला गया:

#!/bin/bash 
read -p "Commit description: " desc 
git add . && \ 
git add -u && \ 
git commit -m "$desc" && \ 
git push heroku master 
+0

"&& \" कमांड के लिए +1 – oak

2
#!/bin/bash 
git pull 
git add . 
git commit -m "$*" 
git push 

टिप्पणी के रूप में cmd ​​आर्ग के साथ कॉल स्क्रिप्ट, कम कुंजी पुश करने के लिए:

$ ./togithub test commit script 
2

निम्नलिखित एक स्क्रिप्ट है कि मैं अपने Git रेपोस संघीय रूप से प्रबंधित करने के लिए उपयोग है - यह अपने मूल शाखा को पुश करने के लिए विकल्प, अपने मचान साइट (यदि सेटअप), और अपने उत्पादन साइट (यदि सेटअप) शामिल होंगे

#!/usr/bin/env bash 

# die script -- just in case 
die() { echo "[email protected]" 1>&2 ; exit 1; } 

# kill message when dead 
KILL="Invalid Command" 

# function to see where to push what branch 
pushing() { 
    git branch 
    sleep 1 
    tput setaf 1;echo What Branch?;tput sgr0 
    read -r branch 
    tput setaf 2;echo Where to? You can say 'origin', 'staging', or 'production';tput sgr0 
    read -r ans 
    if [ "$ans" = "origin" ] || [ "$ans" = "staging" ] || [ "$ans" = "production" ] 
    then 
     git push "$ans" "$branch" 
    elif [ "$ans" = "no" ] 
    then 
     echo "Okay" 
    else die "$KILL" 
    fi 
} 

# function to see how many more times 
more() { 
    tput setaf 2;echo More?;tput sgr0 
    read -r more 
    if [ "$more" = "yes" ] 
    then 
     pushing 
    elif [ "$more" = "no" ] 
    then 
     die "Goodbye" 
    else die "$KILL" 
    fi 
} 

# get the root directory in case you run script from deeper into the repo 
gr="$(git rev-parse --show-toplevel)" 
cd "$gr" || exit 
tput setaf 5;pwd;tput sgr0 

# begin commit input 
git add . -A 
read -r -p "Commit description: " desc 
git commit -m "$desc" 

# find out if we're pushin somewhere 
tput setaf 2;echo wanna do some pushin?;tput sgr0 
read -r push 
if [ "$push" = "yes" ] 
then 
    pushing # you know this function 
    until [ "$more" = "no" ] 
    do 
     more # you know this function 
    done 
elif [ "$push" = "no" ] 
then 
    echo "Okay" 
else die "$KILL" 
fi 

मैंने आपको जितनी संभव हो उतनी टिप्पणियां शामिल करने की कोशिश की ताकि सबकुछ समझ सके।

यदि आपके कोई प्रश्न हैं तो मुझे बताएं।

भी

, मैं इस

echo "alias commit='sh /path/to/script.sh" >> ~/.bash_profile source ~/.bash_profile

की तरह इस सेटअप शायद यह किसी को कार्यप्रवाह में तेजी लाने के

1

यह क्या मैं ज्यादातर समय का उपयोग स्थानीय शाखा प्रतिबद्ध करने के लिए है की तलाश में मदद कर सकता है और दूरस्थ शाखाओं के साथ विलय:

यह छोटी बैश स्क्रिप्ट आपको जोड़ने और प्रतिबद्ध करने की अनुमति देती है स्थानीय शाखा, किसी अन्य शाखा में चेकआउट, इसके साथ विलय करें और इसे दबाएं, और फिर भी अपनी स्थानीय शाखा पर चेकआउट करें, ताकि आप काम करना जारी रख सकें।

default="local-dev-whatever-the-name-of-your-local-branch" 
read -p "Enter local branch [$default]: " local 
local=${local:-$default} 
echo "Local branch is $local" 

if [ -z "$local" ] 
then 
bin/git-merge.sh 
else 
    printf "Enter remote branch: " 
    read remote 

    if [ -z "$remote" ] 
    then 
     printf "Cannot continue without remote branch!\n\n" 
     exit 
    fi 

    git add . 
    git add -u 
    read -r -p 'Commit description: ' desc 

    if [ -z "$desc" ] 
    then 
     printf "\nExit: commit description is empty!" 
    fi 

    git commit -m "$desc" 
    git checkout $remote 
    git status 
    git merge $local 
    git push 
    git status 
    git checkout $local 
    git status 
    printf "\nEnd local commit on $local; merge and push to branch $remote. Well done!\n" 
fi 
संबंधित मुद्दे