简体   繁体   English

我的自动 git 更新过程应该是什么样的?

[英]What should my automated git update process look like?

I come from a subversion background and recently my company made the switch to git. I used to have a cron entry, on my laptop, to update the multitude of checkouts, on a nightly basis.我来自颠覆背景,最近我的公司切换到 git。我曾经在我的笔记本电脑上有一个 cron 条目,每晚更新大量结账。 This way, I would be running against current versions of the different components of our system;这样,我将针对我们系统不同组件的当前版本运行; especially the parts that I wasn't actively developing, but had dependencies on.特别是那些我没有积极开发但有依赖性的部分。 I would like to achieve the same thing with git.我想用 git 达到同样的目的。

Here's my old update process with svn:这是我使用 svn 的旧更新过程:

#!/bin/bash -e
checkout="$1"
svn update --accept postpone ${checkout}
# Run a script to report conflicts that I would resolve in the morning.

I've read a lot of blogs posts on the topic and asked around, and I haven't found many consistent answers.我已经阅读了很多关于该主题的博客文章并四处询问,但没有找到很多一致的答案。 Also, none of the solutions I've seen so far are complete to the extent that I am looking for.此外,到目前为止,我所看到的解决方案都没有达到我正在寻找的程度。 I've taken all those opinions and created the script below.我采纳了所有这些意见并创建了下面的脚本。

How should I deal with submodules?我应该如何处理子模块?

Are there situations, or gotchas, I have not accounted for?是否存在我没有考虑到的情况或陷阱?

#!/bin/bash -e
checkout="$1"
now=$(date +%Y%m%dT%H%M%S)
cd ${checkout}

# If you are in the middle of a rebase, merge, bisect, or cherry pick, then don't update.
if [ -e .git/rebase-merge ]; then continue; fi
if [ -e .git/MERGE_HEAD ]; then continue; fi
if [ -e .git/BISECT_LOG ]; then continue; fi
if [ -e .git/CHERRY_PICK_HEAD ]; then continue; fi

# Determine what branch the project is on, if any.
ref=$(git branch | grep '^*' | sed 's/^* //')

if [[ $ref = "(no branch)" ]]; then
  # The directory is in a headless state.
  ref=$(git rev-parse HEAD)
fi

# If there are any uncommitted changes, stash them.
stashed=false
if [[ $(git status --ignore-submodules --porcelain | grep -v '^??') != "" ]]; then
    stashed=true
    git stash save "auto-${now}"
fi

# If there are any untracked files, add and stash them.
untracked=false
if [[ $(git status --ignore-submodules --porcelain) != "" ]]; then
    untracked=true
    git add .
    git stash save "auto-untracked-${now}"
fi

# If status is non-empty, at this point, something is very wrong, fail.
if [[ $(git status --ignore-submodules --porcelain) != "" ]]; then continue; fi

# If not on master, checkout master.
if [[ $ref != "master" ]]; then
    git checkout master
fi

# Rebase upstream changes.
git pull --rebase

# Restore branch, if necessary.
if [[ $ref != "master" ]]; then
    git checkout ${ref}
fi

# Restore untracked files, unless there is a conflict.
if $untracked; then
    stash_name=$(git stash list | grep ": auto-untracked-${now}\$" | sed "s/^\([^:]*\):.*$/\\1/")
    git stash pop ${stash_name}
    git reset HEAD .
fi

# Restore uncommitted changes, unless there is a conflict.
if $stashed; then
    stash_name=$(git stash list | grep ": auto-${now}\$" | sed "s/^\([^:]*\):.*$/\\1/")
    git stash pop ${stash_name}
fi

# Update submodules.
git submodule init
git submodule update --recursive

Thank you.谢谢你。

I got this error when I had duplicate submodule request in my.gitmodules file.当我在 my.gitmodules 文件中有重复的子模块请求时,我得到了这个错误。

You need to check if there are changes in the submodules as well. 您还需要检查子模块中是否也有更改。 See git submodule foreach . 参见git submodule foreach

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 gitignore 文件应该是什么样的,只在存储库根目录中添加 git add -A 文件 - What should my gitignore file look like to only git add -A files in repositories root Git遥控器是什么样的? - What does Git remote look like? 我正在写我的第一个Android应用程序。 我的.gitignore应该是什么样? - I'm writing my first Android app. What should my .gitignore look like? 使用Git在IntelliJ上进行Scala:.gitignore应该如何? - Scala on IntelliJ with Git: How should the .gitignore look like? 为什么我的git历史看起来像一棵圣诞树? - Why does my git history look like a christmas tree? Maven +版本控制的目录结构应该是什么样? - What should the directory structure of Maven + version control look like? 当我运行命令时,`git config -e`应该做什么? 我不断收到我要查找的页面不存在的通知 - What should `git config -e` do or look like when I run the command? I keep getting notice that the page I'm looking for doesn't exist 您的项目的第一次提交/分支应该如何在git flow中看起来像 - How should your project's very first commits/branches look like in git flow 为什么我的 git shell 在我的笔记本电脑上看起来像这样:[name@name-Laptop ~ (master *+)]$,但在台式机上不是 - Why does my git shell look like this on my laptop: [name@name-Laptop ~ (master *+)]$, but not on desktop 重命名 repo 后更新 .git 文件的过程是什么? - What is the process to update .git files after renaming repo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM