Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check in single file in Git?

My apologies if this is a silly question but I'm a VSS/VSTS guy trying to convert to Git :)

I cloned a repository and pulled down a load of Visual Studio projects. While working on those projects I noticed that another developer had submitted an invalid .sql file. I fixed that .sql file for them, but am now unsure how to check in just that .sql file

My code changes are all half-baked so they can't be checked in at present. I have Git Extensions on my computer, and when I right click on the file in Windows Explorer and go Git Extensions -> Commit, there are lots of files referenced on the left. The file I want to check in has a symbol of a pencil, and the mass of other files all have a green + symbol.

like image 887
plenderj Avatar asked Aug 16 '11 14:08

plenderj


People also ask

How do I commit a single file in git?

To add and commit files to a Git repository Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository. For the <commit_message>, you can enter anything that describes the changes you are committing.

How do I checkout a specific file from a commit?

Find the commit ID of the version of the file you want to revert to. Find the path to the file you want to revert from the working directory. In the terminal, change directories to the working directory. Type git checkout [commit ID] -- path/to/file and hit enter.


1 Answers

you only need to add the changes in the sql file to the index and run git commit.

git add path/to/file.sql
git commit -m 'fixed broken sql file'

don't worry about your other changes, as long as you haven't added them, they won't be committed (to make sure there are no changes in the index, run git reset before adding the other change)

like image 58
knittl Avatar answered Oct 20 '22 01:10

knittl