Skip to content

Create snapshot commits on a not checked-out branch without touching the working tree or losing staged changes

Notifications You must be signed in to change notification settings

meribold/git-snap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 

Repository files navigation

git snap creates a commit that includes most local changes on a user- and machine-specific snapshots branch. It doesn't ask for a commit message. It also doesn't touch the working tree, saves and restores the index, and switches back to the branch that was checked out before running git snap. In other words, everything looks the same as before after running git snap, but your changes are safely stored by Git and can be pushed to a remote for redundancy or sharing. This is in contrast to stashes.

Usage

git snap

This creates a commit with most local changes on a branch named snapshots-<username>-<hostname>. There are no options or parameters. Take a look at the snapshots-meribold-smial branch of this repository to see some commits created using git snap.

Installation

Save git-snap to some directory in your $PATH and make it executable. E.g.:

curl -f https://raw.githubusercontent.com/meribold/git-snap/v1.1.3/git-snap > ~/bin/git-snap
chmod +x ~/bin/git-snap

What gets included in a snapshot commit?

The version of a file that gets committed is always the one in your working tree. Which files are included depends on the working tree and the index: only files that exist in both go into the snapshot commit. In particular:

  • If a file doesn't exist in the working tree, it doesn't go into the snapshot commit.
  • If a file is neither tracked nor staged, it doesn't go into the snapshot commit.
  • If a file is staged for deletion, it doesn't go into the snapshot commit.

Each row in the following table specifies whether a file exists in any of four trees: the working tree, the index, HEAD, and the tip of the snapshots branch. The last column indicates whether git snap would include this file in the commit it creates. The version that is included is always the one from the working tree.

working tree index HEAD tip of snapshots branch description effect
exists exists exists exists tracked file 〰️ updated to working tree version
exists exists exists '' added to snapshots branch
exists exists exists untracked but staged file 〰️ updated to working tree version
exists exists '' added to snapshots branch
exists exists exists after git rm --cached removed from snapshots branch
exists exists ''
exists exists untracked and unstaged file removed from snapshots branch
exists ''
exists exists exists tracked file, after rm removed from snapshots branch
exists exists ''
exists exists untracked file, staged and then removed removed from snapshots branch
exists ''
exists exists after git rm removed from snapshots branch
exists ''
exists after git rm and committing removed from snapshots branch

Similar projects

  • Dura is a background process that automatically creates commits similar to those created by git snap.

About

Create snapshot commits on a not checked-out branch without touching the working tree or losing staged changes

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages