Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minecraft - Versioning your saves

Minecraft - Versioning your saves

This is a tutorial show how to version your saves using Git.

Q: Why would anyone go through this process?
A: Because if you do, you can undo an otherwise un-undoable action, such as swimming in a pit of lava and accidentally dropping your Notch armpit forged special edition diamond pickaxe and your 35 stacks of cobblestone.

Step by step tutorial

Download and install the appropriate version of Git

  • Linux
    • Ubuntu/Debian
      1. sudo aptitude install git
    • Other dists
      1. Use the source, Luke.
  • Windows
    1. Download msysGit
      I would choose the "Full installer for official Git 1.7.4" -- or in a few years; "Full installer for official Git \d(.\d(.\d)?)?"
    2. Install it!
  • Mac
    • I'd love to provide more details, but I do not have access to a Mac OS X environment.
      Installers are found on the git-osx-installer download page. I wish you good luck even though I am sure it is no more confusing than the Windows installer.

Find your saves directory

  • Windows
    • As described in a post on the Minecraft forum
      1. Open "Run" from the start menu
      2. Enter %appdata%/.minecraft/saves in the box
      3. Press RETURN If this does not take you to a folder looking somewhat like this, check the forum thread for further directions.
        My saves folder
  • Linux
    • I can't confirm this, but I suspect it might be in $HOME/.minecraft/saves
      A StackExchange Gaming post confirms that the save folder is indeed located at ~/.minecraft/saves
  • Mac

The worlds are all logically named after this view in minecraft:
My minecraft saves

Set up the git repository

If any of the things mentioned in this section should spawn questions in your head that you absolutely want answered, try the Git Immersion git tutorial. It will teach you git from the bottom and up.

If the Git Immersion tutorial does not answer your questions, try Google. There is an almost infinite amount of posts, discussions and manuals available to answer your questions. Some of them do it better than the others.

This chapter and the following pages of the Git Immersion tutorial concerns the points mentioned in this tutorial.

The only difference between this case and the cases mentioned in the Git Immersion tutorial is that we are mostly dealing with binary files and not text files.

  1. Fire up your command-line interface.

    • Windows
      • StartProgramsGitGit Bash
    • Mac
      • Spotlight ⇒ Search for "Terminal" — Or something similar to this
    • Linux
      • Well, duh. Hints: "Terminal", xterm etc.
  2. Change the current working directory for your command-line-interface to the appropriate World[1-5] folder in the saves directory

    cd /c/Users/YOURNAME/AppData/Roaming/.minecraft/saves/World1
    

    for World 1.

  3. Initialize the git repository

     git init
    

    git-init

     # Notice the dot
     git add .
     
     # You might add -s after, If you have set up your user.name and user.email values in your git configuration
     git commit -m "Initial commit"
    

    git add . should output nothing but a blank space. git commit [...] should output something like this
    git-commit

You now have a snapshot of your selected minecraft world.

The correct way to do something really stupid and unnecessary

  1. Run

    git add .
    git commit -m "Before stupidly walking into lava, an event which I have not at all planned. This is just in case"
    

    This creates a new save point for you, a savepoint that you can revert back to.

    By running

    git log
    

    you should be able to see the "savepoint" or commit, as git calls it. Mine is called "Befor(e) dying". git-log

  2. Load your world

  3. Do something clumsy, unfortunate or just plain stupid.
    found-lava
    fffffffuuuuuuuuuuuu

  4. ?????!?!?!?!

  5. Run

    git log
    

    this will show you the most recent commits with the most recent commit at the top
    git-log

    You will need the SHA1 value that is associated with the specific commit. In this case 07c1925969e2bd30fa4e940656c7ab8573f1ddb0.

  6. Run

    git reset --hard y0ursha1c0mm1774gv41u3
    # WARNING: This step is to my knowledge irreversible; once you back, you never go back.
    

    this will return

    HEAD is now at l0l0l0l Before stupidly walking into lava, an event which I have not at all planned. This is just in case
    

    git-reset

@bacongobbler

This comment has been minimized.

Copy link

commented Sep 5, 2013

Awesome. Scripting the saves via a cron job (say, every 20 minutes) would also be really handy for server backups. Not sure what the equivalent of a cron job would be in Windows though.

@DanielBaulig

This comment has been minimized.

Copy link

commented Oct 27, 2013

@bacongobbler: Windows has a feature called "Scheduled Tasks" which provides functionality similar to cronjobs.

@Finomnis

This comment has been minimized.

Copy link

commented Sep 17, 2014

@bacongobbler: being a minecraft server admin, I actually already tried that. Problem is, after 1 month (with active users), your git repository will be ~100GB large.

@AshleyYakeley

This comment has been minimized.

Copy link

commented Sep 24, 2014

Is there anything that should be in the .gitignore?

@Saucy

This comment has been minimized.

Copy link

commented Feb 16, 2015

I use this in my .gitignore file:

# Ignore everything:
*

# Except for .gitignore
!.gitignore

# Except for any subfolder
!*/

# Your world name
!world/**/*

Seems to be working fine.

@stwobe

This comment has been minimized.

Copy link

commented Jun 2, 2017

Excellent, I've had a go of this sort of thing tonight, before googling it. I was git adding the whole .minecraft folder! I was able to create new branches and switch between them, but was unable to merge them to master, due to merge conflicts. So I'll try your suggested method - to just track one world at a time. Anyone else tried merging branches, so you can just switch between dev and master, say?

....

Update: I made a "Git Shop" with signs displaying the commands from your Gist (close versions anyway) - see screenshots - http://imgur.com/a/VNzY3

Note: Just noticed how old this gist is..

@kaanozcan

This comment has been minimized.

Copy link

commented Aug 9, 2018

Would you recommend this method for distributing the saves on different computers given it wont be played on both computers in the same time?

@equalent

This comment has been minimized.

Copy link

commented Nov 23, 2018

Would you recommend this method for distributing the saves on different computers given it wont be played on both computers in the same time?

Git is not really for binary data. Subversion (SVN) or Perforce (P4) are better for saving worlds and server data.
If you really want to use Git, use Git LFS (your life will be easier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.