Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I commit only some files?

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

How do I commit only these files?

like image 871
Nips Avatar asked Aug 30 '11 06:08

Nips


People also ask

How do I commit individual files?

Try git commit -m 'my notes' path/to/my/file. ext , or if you want to be more explicit, git commit -m 'my notes' -- path/to/my/file.

How do I not commit a specific file?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

Can we commit single file in git?

1 Answer. Then you can git commit a single file directory.


1 Answers

I suppose you want to commit the changes to one branch and then make those changes visible in the other branch. In git you should have no changes on top of HEAD when changing branches.

You commit only the changed files by:

git commit [some files] 

Or if you are sure that you have a clean staging area you can

git add [some files]       # add [some files] to staging area git add [some more files]  # add [some more files] to staging area git commit                 # commit [some files] and [some more files] 

If you want to make that commit available on both branches you do

git stash                     # 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 
like image 182
Alexander Oh Avatar answered Oct 16 '22 09:10

Alexander Oh