I just created a big piece of code I want to commit in several separate commits.
So I can stage relevant parts, commit, stage, commit, ... and so on until I have all my changes commited.
The missing part is how can I test whether I split the commit correcty.
I.e. whether the part that is in staging area at least compiles?
To do that I must somehow bring my work tree to be in sync with index (staging area) without losing the changes to be committed later.
What is the right way to do it?
What is the quickest way to do it?
Update:
How to do it with magit?
Typical Workflow are as follows Get local copy of code. Create a branch. Edit files. Add and commit changes to local machine. Get back in sync with changes commited by others.
Git tracks file changes by the user creating a save point, or in Git terms a commit. Each commit takes a snapshot of the current file system rather than storing just the changes made since the last commit. This allows a commit ot be extracted and the whole history not required to rebuild the file system.
You could do it with:
$ git branch task1 # first set of commit to do
An intermediate branch can be useful to record some intermediate commits when you are slowly adding some content to the index.
Then try an interactive session for adding just what you want:
$ git add -i
Add any time you want to check what you have added:
$ git stash --keep-index
If it compiles, git commit
your current work, and if task1
is not yet complete, git stash pop
to restore the full working tree and repeat.
Once task1
is fully baked, you can trim all those 'task1
' commits, and merge the all work in master:
$ git checkout master
$ git merge task1
$ git branch -D task1 # no need for that intermediate branch
If you want to conserve the history of some significant task1
commits, you can rebase first task1
on top of master, before merging master
in task1
(fast-forward)
Finally, if your stash still contains some work in progress, repeat the all process for task2
.
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