版本仅在我询问时才从目录控制文件,而不是整个目录的初始完整提交?

时间:2014-03-15 07:14:23

标签: git svn version-control github

我是否可以将某个文件放在某些VCS中,例如git / subversion / etc,“当我正在修改它时”。所以首先我把未经修改的版本&然后修改版本。希望只在我想要的时候将文件放在VCS中,而不是进行初始的完整目录提交。这可能吗?

我想对我在ubuntu服务器上修改的一些配置文件进行版本控制,但我希望不要进行初始的完整目录提交,而是在查看是否可以在我之前向VCS添加文件我正在修改文件..我怎么能实现这个目标?

1 个答案:

答案 0 :(得分:0)

我编写了一个自定义脚本来处理在编辑文件之前保持文件的默认状态。目前的状态。 [只有这两个版本的每个修改过的文件]。它们的差异(默认状态和当前状态)可用于跟踪我所做的所有总变化。这不会保留版本的更改版本。但是,这可用于计算我对系统上的文件所做的所有自定义。因此也可以用于其他系统的后续再生。 请注意,这不会提供备份,而是提供其他备份旁边的其他数据,以便使用我的配置轻松重建新系统。

这是脚本。 (我会在对任何配置文件进行任何更改之前执行它):

#!/bin/bash   

# This is script to remember default & current state of manually edited configuration files.. from anywhere on system..     
# the diffs between current & default may be used to regenerate configurations on another machine.
# Only when used for first time on  a file, it is stored in default state directory otherwise stored in current state directory..

# $1 - 1st passed parameter... this should be subject file  

DEFAULT_STATE_DIR="/root/state-default/" 
CURRENT_STATE_DIR="/root/state-current/" 

FILE=$1

# create the DEFAULT_STATE_DIR & CURRENT_STATE_DIR directories if they dont yet exist.. 
if [ ! -d "$DEFAULT_STATE_DIR" ]; then  
  mkdir $DEFAULT_STATE_DIR
fi
if [ ! -d "$CURRENT_STATE_DIR" ]; then  
  mkdir $CURRENT_STATE_DIR
fi

# fail incase user did not provided full file path(starting from /) in parameter
if  [[ $FILE==/* ]]; then   
    echo "Proceeding.."
else
    echo "Specify full File path starting with /"
    echo "Will stop now."
    exit 0
fi

# convert all '/' in the file path to '-', so the name used contains hint about path as well
FILENAME_TO_USE=$(echo "$FILE" | sed 's;/;-;g')     



if [ -f $DEFAULT_STATE_DIR/$FILENAME_TO_USE ]; # if default state is already stored..then store this as current state..
then
   echo "Initial state for File $FILE already stored. Storing as current modified state.."
   cp $FILE $CURRENT_STATE_DIR/$FILENAME_TO_USE
   echo "Modified."
else
   echo "Initial state for File $FILE didn't existed. Storing the current state as initial state of this file.."
   cp $FILE $DEFAULT_STATE_DIR/$FILENAME_TO_USE
   echo "Added."
fi