How to make a temporary checkpoint (rather than commit)?

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

However, I am not ready to commit.

Is it possible to make a checkpoint to which I can return? Git stash does not seem appropriate in this case, since I want to work with the same branch.

+6
source share
4 answers

Why do you want to work in one branch? Create a new branch, say git checkout -b experimental/ni_shrubbery , commit to it, then either merge it or don’t. You can always go back to your master or develop or feature/shrubbery , no matter what you develop. Branches exist specifically for this scenario. Just do not push this branch, and all your work is local until you merge into the branch that you push.

+8
source

Local commit is exactly what you want: a reference point to which you can return. Local commits can be changed / compressed / deleted before publishing them, so you don’t need to “be ready to commit”. You should be ready to push (for example, squash all your local commits into 1 commit before clicking). You can learn more about local commit modifications in the ProGit book (I refer to the " Rewrite History" section, but suggest you read all the chapters)

+2
source

Just lock. You can always roll it back or combine it when you are happy. Until you push it to your remote repositories, no one will see it.

My git motto is "commit earlier and commit often - clean it before clicking."

Another option is to create a branch. Then all your experimental goals will live separately from the captain. You can merge or reinstall them as soon as you finish experimenting.

0
source

Make a fix. Give him a message like "intermediate commit" or something else. Then cut the branch and start work from there. If you want to avoid the latest changes (i.e. those that you just made), cut the branch from HEAD^ and work from there.

If you are happy with the state of affairs after your experiment, you can move your master (or any branch you were in) to the current HEAD , thereby discarding the temporary commit. If you want an intermediate commit, go back to master , reset to HEAD^ , rework it, commit, and then merge the experimental branch into master .

If you do not like your experimental work, just omit this branch, return the master and reset to HEAD^ .

The entries are very lightweight and it is perfectly normal to use them that way.

0
source

Source: https://habr.com/ru/post/974133/


All Articles