Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a temporary checkpoint (not a commit)?

Tags:

git

I am working on a project and I am about to do something experimental.

I am not ready to make a commit however.

Is it possible to make a checkpoint that I can revert to? Git stash does not appear to be appropriate in this case as I want to work on the same branch.

like image 721
Caster Troy Avatar asked Aug 21 '14 01:08

Caster Troy


People also ask

How do you commit on checkpoints?

Commit is to be performd by user to save data permenntly.. And checkpoint is process, it is occurd when logswitch occurs (means when LGWR switch from one RL File to another) to save data to Datafile permenently. Checkpoint can happen at any time.. Before, after or at the time of commit.

Do you have to commit before stashing?

Git has an area called the stash where you can temporarily store a snapshot of your changes without committing them to the repository. It's separate from the working directory, the staging area, or the repository.


1 Answers

Main drawback of committing your changes - whether to a temporary experimental branch or not - is that one loses track of overall extent of work - the combined changes performed up to the checkpoint.

In an IDE, I personally use IntelliJ IDEA, I can see colour blocks in the gutter (near scrollbar) which indicate which lines were edited or added. Deleted blocks of code are indicated by a little clickable triangle, and I can easily see what those deleted lines were by clicking on it.

All this neat IDE stuff works only up to the point you commit your changes.

So, what I would like to suggest is a combination of the above answers - i.e. do commit often and early, potentially edit/rewrite your commit history before pushing/publishing your changes to the remote. Also, after you've committed you perform a soft reset. git reset --soft HEAD^ This way, you will (1) have a commit in your git repo that you can roll back to, if needed. (Use git reflog to get at the hash of the commit, should you later need to revert back to it.) You also (2) get to keep all changes as un-committed so that your IDE can show you the visual indicators of change.

If you make really bad changes you want to quickly abandon, do a hard reset back to your most recent good checkpoint, then a soft reset to the point where you started making your big changes.

like image 125
Peter Perháč Avatar answered Sep 21 '22 14:09

Peter Perháč