2012-07-10 56 views
1

我已經寫了一個腳本來確定重定位。不能說不知道哪個分支要重新對齊

當我運行$ my-rebase,我得到一個錯誤:

You asked me to pull without telling me which branch you want to rebase against, and 'branch.rohan_branch1.merge' in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. 'git pull '). See git-pull(1) for details.

If you often rebase against the same branch, you may want to use something like the following in your configuration file:

[branch "rohan_branch1"] 
remote = <nickname> 
merge = <remote-ref> 
rebase = true 

[remote "<nickname>"] 
url = <url> 
fetch = <refspec> 

我有主分支(工作拷貝),然後我創建rohan_branch1;在某些時候,我似乎在主人身上做了重新設定。

現在我想保持rohan_branch1是最新的。我怎樣才能擺脫這個錯誤?

+2

這將是張貼你的腳本 – CharlesB 2012-07-10 06:22:39

+0

注意了Git 1.8.5將引入一個有用[巧妙的方法來保存對合並'拉--rebase'(HTTP ://stackoverflow.com/a/18756102/6309) – VonC 2013-09-12 05:37:50

回答

3

如果你想拉時(git pull --rebase)變基,則需要與當地的分支相關聯的上游分支在其上拉至:

git branch --set-upstream rohan_branch1 nickname/anotherBranch 

(如CharlesB描述「git rebase origin」 vs.「git rebase origin/master」)

從那裏,你可以考慮gup script (from "gup: A friendlier git pull --rebase")Jason Weathered

function gup 
{ 
    # subshell for `set -e` and `trap` 
    (
    set -e # fail immediately if there's a problem 


    # use `git-up` if installed 
    if type git-up > /dev/null 2>&1 
    then 
     exec git-up 
    fi 


    # fetch upstream changes 
    git fetch 


    BRANCH=$(git symbolic-ref -q HEAD) 
    BRANCH=${BRANCH##refs/heads/} 
    BRANCH=${BRANCH:-HEAD} 


    if [ -z "$(git config branch.$BRANCH.remote)" -o -z "$(git config branch.$BRANCH.merge)" ] 
    then 
     echo "\"$BRANCH\" is not a tracking branch." >&2 
     exit 1 
    fi 


    # create a temp file for capturing command output 
    TEMPFILE="`mktemp -t gup.XXXXXX`" 
    trap '{ rm -f "$TEMPFILE"; }' EXIT 


    # if we're behind upstream, we need to update 
    if git status | grep "# Your branch" > "$TEMPFILE" 
    then 


     # extract tracking branch from message 
     UPSTREAM=$(cat "$TEMPFILE" | cut -d "'" -f 2) 
     if [ -z "$UPSTREAM" ] 
     then 
     echo Could not detect upstream branch >&2 
     exit 1 
     fi 


     # can we fast-forward? 
     CAN_FF=1 
     grep -q "can be fast-forwarded" "$TEMPFILE" || CAN_FF=0 


     # stash any uncommitted changes 
     git stash | tee "$TEMPFILE" 
     [ "${PIPESTATUS[0]}" -eq 0 ] || exit 1 


     # take note if anything was stashed 
     HAVE_STASH=0 
     grep -q "No local changes" "$TEMPFILE" || HAVE_STASH=1 


     if [ "$CAN_FF" -ne 0 ] 
     then 
     # if nothing has changed locally, just fast foward. 
     git merge --ff "$UPSTREAM" 
     else 
     # rebase our changes on top of upstream, but keep any merges 
     git rebase -p "$UPSTREAM" 
     fi 


     # restore any stashed changes 
     if [ "$HAVE_STASH" -ne 0 ] 
     then 
     git stash pop 
     fi 


    fi 


) 
} 

不是直接調用git pull --rebase,它會管理未跟蹤的文件(存儲),並在重新綁定時保留合併提交(git rebase -p)。
(請參閱「Rebasing Merge Commits in Git」,從「Envato Notes blog」)

相關問題