When using Git it is possible to stage files as per https://githowto.com/staging_changes. So typically
git add file1
git commit
git add file2
git commit
What I can't see however is a way to create multiple stages (so I can split up a large editing session) that can be saved with a single commit. Is this even possible with Git?
The way Git is used is usually like this:
Hence if you want to commit a subset of the modification resulting by a long editing session, just stage only some files and commit those. As usual, the advice is to keep your changes in a small related set inside a commit, avoiding at all costs the huge meaningless commit of unrelated changes.
An update regarding branches: If what you need is to put aside some changes you created on the master branch and work on something else, you could store temporarily your changes on another local branch, such as:
- create a new branch called "temp_changes" (new branch);
- switch to it (checkout);
- stage the editing you want to store in this branch
- commit the stage;
- switch back to master branch (checkout);
Thereafter you could work on master branch unaffected by those modification that now are stored in _temp_changes_ branch only. You could also push this branch remotely if you need to share it with anyone else or to store it safely.
The simple answer is 'no'.
Git only allows only one single staging area.
Although it could help to have them in many situations, because work is not always linear.
There do exist solutions to rewrite history after the changes have been commited, like rebasing or 'fixups', but this is not the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With