So there are many times that while working with git I follow this process:
- Clone a project and perform it's setup.
- The setup/install process creates new files which maybe configurational files specific to my environment (that aren't gitignored) or modifies existing "core" files in the process of the setup of the project. These changes/files are essential to run the project but should not be checked into the repo and were coded specifically that way so that these should NOT be checked in ever coz it maybe sensitive.
- I make a branch called feature-newfeaturename and then start my feature development. At this point there are several unstaged changes/files from step 2 and I work on top of that.
Now when I finish developing the feature, I want to checkin merely the changes I made excluding the files. Normally what I do is that at the end of step 2, I do a git diff > setup-changes.txt
and then use that file as reference at the end.
When I'm done with my feature development, I literally do git checkout each-file-name-in-the-list
, followed by git add .
and git commit
and then make the PR--this way it merely PRs in my changes only.
This works fine for now but isn't efficient and I feel there might be a better way?
And another issue is, sometimes my changes include changes to the core files which conflict with the changes made in step 2. So when I do a git checkout in the end, my changes would be erased and therefore I have to manually diff out the changes I made, do a checkout of the file with the original core (that excludes the setup changes) and then manually use the diff to find and add my changes alone.
Again this is counterintuitive and wish there is a better process. Is there? If so how?
To simplify this question, let me provide an example:
- There's a file main.txt which simply has the word 'apples' and is part of "first commit" in the main branch.
- Then I do a
git checkout -b setup
and add bananas which is the configuration changes and perform a commit. - Then I do a
git checkout -b feature
from setup branch and add oranges making the file have apples, bananas and oranges. So the new feature is addition of oranges.
Now what I want to do is simply get the diff between first and last i.e. I want to be able to have just apples and oranges in my final commit and then push that as the second commit to my main branch.