Reputation: 1674
This is kind of a hard question to explain, mainly because I still don't know a whole bunch about git.
I just know the basics to be able to get by.
Currently I've been working on a bigger project and have changed a bunch of lines in a specific file. The update that I'm working on is still a ways away from being committed and pushed to git.
Lone behold there ended up being a smaller update that I had to make within that same file and now need to push that code instead of the semi working file currently.
Is there any way that I could stash certain lines of that file so that the bigger changes I made to that file don't get lost when I decide to push the smaller changes?
Or do I have to stash what I currently have now, and then go back into the file and remake the smaller changes again and push that?
Sorry if this is hard to understand, it's kind of difficult to explain, plus I don't know if there is a way of currently doing this with git anyways.
EDIT
I'm looking into using separate branches just like the second answer suggests. This seems like a more efficient solution, and will allow me to keep track of my fixes.
Upvotes: 13
Views: 6518
Reputation: 1236
You can stash specific lines from files by using the --patch option:
git stash push --patch
git stash push --patch <filename>
Git will ask you interactively what you want to do with each file. You can edit the files or choose which lines get stashed
Note that you can also do this when adding files to your staging area with git add:
git add --patch <filenames>
If what you want to do is commit part of a file, you can stage the part you want to commit with git add --patch, and there is no need to stash.
Upvotes: 17
Reputation: 1624
Read about git branches, which allow you to work on fixes to multiple aspects of a project separately.
You should create one branch for the big ongoing changes, and a separate branch for the smaller update.
Example with more details: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
Upvotes: 2