我来自颠覆背景,最近我的公司转而使用git。我曾经在我的笔记本电脑上有一个cron条目,每晚更新大量的结账。这样,我将针对我们系统的不同组件的当前版本运行;特别是我没有积极开发但有依赖性的部分。我想用git实现同样的目的。
这是我使用svn的旧更新过程:
#!/bin/bash -e
checkout="$1"
svn update --accept postpone ${checkout}
# Run a script to report conflicts that I would resolve in the morning.
我已经阅读了很多关于这个主题的博客帖子,并且四处询问,我没有找到很多一致的答案。此外,到目前为止,我所看到的解决方案都没有达到我想要的程度。我已经采取了所有这些意见并创建了下面的脚本。
我应该如何处理子模块?
是否有情况或陷阱,我没有考虑过?
#!/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
谢谢。
答案 0 :(得分:0)
您还需要检查子模块中是否有变化。请参阅git submodule foreach
。