Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I have two projects. One is the "official" project and the second is a light modification (some files added). I created a new branch and I put new files to them. But during development, some files common to both branches are changed.

How do I commit only these files?

1 Answer

0 votes
by (50.2k points)

For this question, you need to commit the changes to one branch and then make those changes visible in the other branch. you don't need any changes on top of HEAD when changing branches.

You commit only the changed files by:

git commit [some files]

if you have a clean staging area then you can

git add [files]       # add [files] to the staging area

git add [more files]  # add [more files] to the staging area

git commit                 # commit [files] and [more files]

To make that commit available on both branches you could do

git stash                     # this will remove all changes from HEAD and save them somewhere else

git checkout <other-project>  # change branches

git cherry-pick <commit-id>   # pick a commit from ANY branch and apply it to the current

git checkout <first-project>  # change to the other branch

git stash pop                 # restore all changes again

Browse Categories