How can I avoid an accidental dcommit from a local branch

前端 未结 3 545
孤独总比滥情好
孤独总比滥情好 2020-12-10 15:10

Sometimes, I create local branches in git, and I\'d like to get a warning message when I try to dcommit from them.

How can I prevent myself from accidentally dcommit

3条回答
  •  不知归路
    2020-12-10 15:40

    In case anyone else needs this for Windows Powershell:

        function CallGit
        { 
            if (($args[0] -eq "svn") -And ($args[1] -eq "dcommit")) {
                $curr_branch = &{git branch};
                $curr_branch = [regex]::Match($curr_branch, '\* (\w*)').captures.groups[1].value
                if ($curr_branch -ne "master") {
                    Write-Warning "Committing from branch $curr_branch";
                    $choice = ""
                    while ($choice -notmatch "[y|n]"){
                        $choice = read-host "Do you want to continue? (Y/N)"
                    }
                    if ($choice -ne "y"){
                        return
                    }
                }
            }
            &"git.exe" @args
        }
        Set-Alias -Name git -Value CallGit -Description "Avoid an accidental git svn dcommit on a local branch"
    

提交回复
热议问题