Zeynel
Zeynel

Reputation: 13515

How to commit just one file in a directory?

I've been learning Go and I created a directory as recommended as C:\Users\A\Desktop\go and in the go directory I have bin, src and pkg. In src, I have a folder "play" where I put all tutorial and exercises and code. In git bash I cd to C:\Users\A\Desktop\go and do git init and git add . When I do git status I get a list of hundreds of files including tutorials, exercises etc. But I just want to commit one file which is wiki.go and its related files. How do I do that? I read several tutorials but cannot figure this out. And I am working alone on this code.

Upvotes: 0

Views: 218

Answers (3)

user456814
user456814

Reputation:

The original poster states:

I just want to commit one file which is wiki.go and its related files.

I'm assuming that the wiki.go and its related files are under the src/play directory, as the original poster states:

In src, I have a folder "play" where I put all tutorial and exercises and code.

So to add wiki.go and related files, just pass the folder path to git add:

$ git add <directory of wiki.go>

You can read more about how to use the git add command at the official Linux Kernel Git documentation.

Upvotes: 1

cforbish
cforbish

Reputation: 8809

After the git init, to just commit just wiki.go you would:

git add wiki.go
git commit -m 'Add wiki.go.'

The git add . will add all the files which would make the next git commit add them all.

Upvotes: 3

ouah
ouah

Reputation: 145829

To commit only file my_file, just do:

git commit my_file

Upvotes: 2

Related Questions