首页 > 解决方案 > 在 bash_profile 中自定义 git 命令以自动索引到下一个分支

问题描述

下面是我的自定义 gitp 命令,效果很好(使用伪代码)。我想通过让它自动自动索引并结帐到新分支来添加到脚本中。希望有一个命令行 bash 高手可以解决这个问题!:)

    previous_branch_num = 0;
    gitp() {
      git add -A &&
      git commit -m "${1?'Missing commit message'}" &&
      git push      
      git checkout -b "v{++previous_branch_num}" //<--psuedo code
    } 

标签: linuxbashgitterminalgit-bash

解决方案


简单地:

#!/bin/bash

previous_branch_num=0

gitp() {
  git add -A &&
  git commit -m "${1?'Missing commit message'}" &&
  git push      
  git checkout -b "v$((++previous_branch_num))" # <-- real code
} 

推荐阅读