iteahaus

back it up

If you read my last post, you’re probably thinking, instead of running three commands, why not just copy the file and go home?

$ cp -p moneyhoney.js moneyhoney.js~
$ svn revert moneyhoney.js

Three reasons:

  1. git gives you versioning.
  2. I have a bash function for you.
  3. git gives you versioning.

You can put this in your .profile:

backup () {
  if [[ $# -ne 0 && -e "$@" ]]; then
    if [ ! -d .git ]; then
      if [ -e .git ]; then
        echo ".git EXISTS AND IS NOT A DIRECTORY."
        return 1
      fi
      git init .
      return=$?
      if [ $return -ne 0 ]; then
        return $return
      fi
    fi
    git add "$@"
    return=$?
    if [ $return -ne 0 ]; then
      return $return
    fi
    git commit -m "$FUNCNAME()" "$@"
  fi
}

So now you can do this instead:

$ backup moneyhoney.js
$ svn revert moneyhoney.js