1

我写了一个做变基的脚本。

当我运行时$ my-rebase,我得到一个错误:

您要求我拉动,但没有告诉我您要针对哪个分支进行变基,并且您的配置文件中的“branch.rohan_branch1.merge”也没有告诉我。请在命令行中指定您要使用的分支,然后重试(例如“git pull”)。有关详细信息,请参阅 git-pull(1)。

如果您经常针对同一个分支进行变基,您可能希望在配置文件中使用类似以下内容:

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

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

我有主分支(工作副本),然后我创建了 rohan_branch1; 似乎在某个时间点我确实在 master 中进行了 rebase。

现在我想让 rohan_branch1 保持最新。我怎样才能摆脱这个错误?

4

1 回答 1

3

如果你想在拉 ( git pull --rebase) 时变基,你需要有一个上游分支与你要拉到的本地分支相关联:

git branch --set-upstream rohan_branch1 nickname/anotherBranch

(正如CharlesB在“ “<code>git rebase origin” vs.“<code>git rebase origin/master”</a>”中所描述的)

从那里,您可以考虑Jason Weathered的 gup 脚本(来自“gup: A friendlyier git pull --rebase”)

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)。
(参见“ Envato Notes 博客”中的“ Rebase Merge Commits in Git ” )

于 2012-07-10T06:28:39.037 回答