John Doe
John Doe

Reputation: 3233

TFS GIT - How to commit only certain files?

I am new to using Git in TFS.

Say I have 10 files that I modified, however I would only like to commit 2 of those files.

Previously with TFS I could include/exclude what file(s) I wanted to check in.

What would the equivalent be in Git?

Would I Stage my 2 files I want to commit and check those in? Or would I stage the 8 files and commit my 2 changes?

Upvotes: 2

Views: 2428

Answers (5)

Ahmad Pujianto
Ahmad Pujianto

Reputation: 359

Some trick could be used, either individually or combined

  1. Stage only file that you wanted : this way when you push or sync only files already staged will be sent
  2. Stash file : This is usually when you still work on a file but need to get updates on the particular file immediately without needing to push (or sync) it (which cause conflict). Later you can get back the stashed file to replace file from pull.
  3. Undo change (in 'git change' window) then pull : when you change a file but wanted to get what other guys do (and loose your own change)

Upvotes: 0

Chenglong Wei
Chenglong Wei

Reputation: 78

You do not need to state all files: You can git add command to stage the files you want to commit, like:

git add [file1] [file2]

Then use git commit command to commit your change, like:

git commit -m 'commit message'

Upvotes: 0

Tal Avissar
Tal Avissar

Reputation: 10304

  1. go to your root directory
  2. stage the files you want to commit

    git add fileName

  3. commit the files you staged

    git commit -m "my message"

Upvotes: 0

kk.
kk.

Reputation: 3945

To stage all the files for commit from root of your repository you execute git add . There are following 2 ways by which you can stage specific files for commit:

  1. Go to the directory from which files are to be staged for commit e.g. C:\git\repository\{path-to-directory} and execute git add .

  2. Stage files one by one from the root of your directory as git add {file-path}

Once these files have been staged for commit, you can execute git commit -m. This will commit only 2 staged files.

Upvotes: 0

Jacob Maki
Jacob Maki

Reputation: 366

The equivalent in Visual Studio using Git with TFS would be include -> staged.

Here's the link to Microsoft's documentation.

Upvotes: 3

Related Questions