Git shell command alias giving a "bad config file" error

时间:2016-02-12 20:08:56

标签: git bash shell

I'm working on the following git alias

[alias]
  pushup = !git push --set-upstream origin `git branch | egrep "^\*" | awk -F"*" '{print $NF}'`

which is supposed to do a git push while simultaneously setting the upstream to the current branch.

The command

git push --set-upstream origin `git branch | egrep "^\*" | awk -F"*" '{print $NF}'`

works fine by itself on the command-line but I get a bad config file error when I try to use it as a git alias.

Clearly I don't understand something about the format of git aliases. Anyone want to enlighten me?

2 个答案:

答案 0 :(得分:1)

I'm not sure what went wrong, but the following simplified alias works for me:

CREATE PROCEDURE [dbo].[updatestuff]
    @update1 AS udtupdate1 READONLY ,
    @update2 AS udtupdate2 READONLY ,
    @time DATETIME
AS 
    BEGIN       

    SET NOCOUNT ON        

    WHILE (1 = 1)
    BEGIN
       BEGIN TRANSACTION

       UPDATE top (1000)  lms  
          SET     lms.col1 = lsp.col1 ,  
                lms.TimeStamp = @time 
          FROM    dbo.tlivetable1 lms  
                INNER JOIN @update1 lsp ON lms.livetable1Id = lsp.colId   

       IF @@ROWCOUNT = 0 -- terminating condition;
        BEGIN
          COMMIT TRANSACTION
          BREAK
        END

       COMMIT TRANSACTION
    --WAITFOR DELAY '00:00:01'; --<-- you can uncomment wait for delay to increase the delay between batches
    END

    WHILE (1 = 1)
    BEGIN
       BEGIN TRANSACTION

          UPDATE top (1000)  ms
          SET     ms.col1 = lsp.col1 ,
                ms.TimeStamp = @time
          FROM    dbo.tmrks ms
                INNER JOIN @update1  lsp ON ms.mrksId = lsp.Colid     

       IF @@ROWCOUNT = 0 -- terminating condition;
        BEGIN
          COMMIT TRANSACTION
          BREAK
        END

       COMMIT TRANSACTION
    --WAITFOR DELAY '00:00:01'; --<-- you can uncomment wait for delay to increase the delay between batches
    END

    WHILE (1 = 1)
    BEGIN
       BEGIN TRANSACTION

          UPDATE top (1000)  mms
          SET     mms.col2 = msp.col2 ,
                mms.Date = @time
          FROM    dbo.tMMSel mms
                INNER JOIN @update2 msp ON msp.col1Id = mms.MMId
                AND msp.col2Id = mms.MMSId  

       IF @@ROWCOUNT = 0 -- terminating condition;
        BEGIN
          COMMIT TRANSACTION
          BREAK
        END

       COMMIT TRANSACTION
    --WAITFOR DELAY '00:00:01'; --<-- you can uncomment wait for delay to increase the delay between batches
    END

END  

Instead of grepping for [alias] pushup = !git push --set-upstream origin $(git branch | awk '/^*/{print $2}') and then splitting on it, you could rely on *'s splitting on whitespace to automatically get you the branch name as the second field, and use awk do awk's job as well.

Vim highlights grep as an error, and when I try with it, I get the error you got (I'm using \* for debugging :D):

enter image description here

So that's the cause of the error. I still don't know why.

I suppose you could also use the simpler command from this SO post:

echo

答案 1 :(得分:0)

错误的原因是\在解析别名时被识别为转义字符。解析器期望\之后需要转义的内容,但星号不符合要求。

您应该使用第二个反斜杠转义\,以使解析器满意并将其传递给egrep。像这样:

[alias]
  pushup = !git push --set-upstream origin `git branch | egrep "^\\*" | awk -F"*" '{print $NF}'`
相关问题