我想在我的Linux源代码中修补一些文件。对于每个文件,我都要创建一个补丁(强制 :每个编辑的单个补丁)。这是我的回购结构。
在应用新补丁之前,我想要撤消之前申请过的所有补丁。
然后从第一个到最后添加的文件开始修补。
EG;我将002.patch
添加到目录补丁/并且如果已经应用000.patch
和001.patch
,则使用补丁-p0 -R<反向补丁。 "膜片名称" (补丁应用应从001.patch开始,然后是000.patch)。 但是在目录中补丁/将出现三个脚本,我必须选择前两个000和001。
但我发现很难只选择最新补丁之前的补丁
这是我脚本的那部分
echo "Going to reverse all previously applied patches "
#Reversing patches using a for loop "NEED HELP FOR SELECTING THE JUST PREVIOUS PATCHES"
for patch in `ls -lr $PATCHDIR`; do
echo "reversing patch " $patch
patch -p1 -R < $PATCHDIR/$patch
then
echo "Reversing patch $PATCHDIR/$patch failed"
exit 1
fi
done
#Applying patches using a for loop
for patch in `ls $PATCHDIR`; do
echo "Found patch file " $patch
echo "applying patch......"
patch -p1 < $PATCHDIR/$patch
if [ $? != 0 ]
then
echo "Applying patch $PATCHDIR/$patch failed"
exit 1
fi
done
答案 0 :(得分:0)
我不确定我是否完全理解了这里的目标,但这听起来像Quilt这样的东西就是为此设计的。
答案 1 :(得分:0)
我不确定这是你期望的,但为什么不简单地将补丁glob扩展存储在Bash数组中?然后,您可以轻松地在阵列中上下移动。
PATCHES=( $PATCHDIR/*.patch )
for ((i=${#PATCHES[@]}-2; i>=0; i--)); do
# ^
# -2 here to skip the "last one"
patch="${PATCHES[i]}"
echo "reversing patch " $patch
# [...]
done
for patch in "${PATCHES[@]}"; do
echo "Found patch file " $patch
echo "applying patch......"
# [...]
done
话虽这么说,我想你可能有两个设计问题。也许: