【问题标题】:Is it possible to create shell scripts that push only a few of the locally accumulated commit?是否可以创建仅推送少量本地累积提交的 shell 脚本?
【发布时间】:2021-09-08 22:59:23
【问题描述】:

我想使用一个 shell 脚本来自动推送一定数量的远程提交。 自动推送效果很好,但我想做的是,我想手动 git add 和 git commit 并且我只想自动推送。

比如本地有3个commit,推送最旧的commit 3和commit 2,留下最新的commit 1。

git-auto.sh
#!/usr/bin/env sh

baseDir = ~/dev/git-playground
cd ${baseDir}
afewCommits=`git commit | head -n 2` <- don't know how

if [ -z "$afewCommits" ]; then
    echo '##### file not found #####'
    exit
fi

git push

请帮帮我

【问题讨论】:

  • git push origin HEAD^:master

标签: git shell auto


【解决方案1】:

你可以:

  • 确定当前分支的名称
  • 将它(减去 HEAD:最近的提交)推送到其同名的上游分支:
branch-name = "!git rev-parse --abbrev-ref HEAD"
pub = "!f(){ git push -u origin HEAD^:$(git branch-name); };f"

【讨论】:

    猜你喜欢
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 2011-02-05
    • 1970-01-01
    相关资源
    最近更新 更多