Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Stashing specific files before a commit

Tags:

git

I'm not sure if what I'm looking for is a git-stash but here is what I want to do.

I have configuration files customized for local use. Those files already exist in Git. Now, if I add a new feature (change other files), I want to stash my config and hit commit and only commit the files related to my new feature.

If I use git-stash, it stashes everything. How can I stash my config files (only)?

Thanks

like image 711
hbt Avatar asked Dec 16 '22 19:12

hbt


2 Answers

Two things.

  1. You should stage only the files you want to for the commit. This is done using git add. Even if you have a ton of changes, you can stage only the fields (and pieces of files using git add -p) you want to commit using git add. You should be doing this.

  2. Unless your config file is an integral part of your application (and you want to version control it), you should be ignoreing and not even version controlling it.

like image 63
Noufal Ibrahim Avatar answered Jan 06 '23 23:01

Noufal Ibrahim


use git add -p and select only those changes you want to commit. this is good practise anyway, because it acts as a little code review.

like image 37
Alex Brown Avatar answered Jan 06 '23 22:01

Alex Brown