Often while working on a branch I need to introduce some "temporary" changes (such as additional debugging info, or a change which lets me better observe the thing i'm actually working on).
About these "temporary" changes:
Currently I just keep them as unstaged and I skip them manually when staging every commit. However I can't stay with this solution because:
How should I deal with it?
gitignore
is obviously out of the question because I don't want to ignore the whole files and I'm still interested in changes from other committers (I need to rebase the branch to master from time to time).
Here is how to save local changes without commit in Git. Just issue git stash command as shown below from your present working directory which contains unsaved unchanges. This will stash all changes you made and your repository will be restored to your last commit.
The "git stash" command can help you to (temporarily but safely) store your uncommitted local changes - and leave you with a clean working copy.
Stashing your work The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.
I typically deal with this by using:
git add -p
... to stage changes hunk-by-hunk. Then you just have to make sure to press n for your debugging changes.
If I have more involved changes of this type, I'll create a branch called something like local-changes
with a commit at its tip that introduces the debugging code. After creating a few more commits, I'd then use:
git rebase -i master
... to reorder them so that the commit with the local changes is at the tip again. Then to update master and return to the local changes branch, you can do:
git checkout master git merge local-changes^ git checkout local-changes
Try git update-index --assume-unchanged <file>
. This way git will not add the file to the index when using git add
or git commit -a
.
EDIT: This doesn't allow you to deal with the case of having one file with both temporary and permanent changes.
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