top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How git commit on a folder?

+1 vote
94 views

What it means to git when I try to commit on the local folder.for example "git commit ."
Is there any real use case for this?

posted Mar 6, 2014 by Sanketi Garg

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote

You can easily commit folder like below:

git init
mkdir folder_name
touch folder/file_name
git add folder_name
git add folder_name/file_name
git commit -m "adding files"
answer Mar 6, 2014 by Amit Kumar Pandey
0 votes

Depends on how you're looking at it. A commit in Git is a snapshot of the whole repository so it doesn't matter where in the tree did you run git commit.

The tricky part, however, is that "." argument in your example. git commit accepts pathnames, and if they are specified, they substantially change its behaviour: normally git commit records the new commit based on the *staged* changes: changes added to the staging area (also "the index") by means of the git add command; specifying pathnames make git commit ignore these changes completely and record
the new commit using the current (as in the work tree) state of the files passed to git commit. In your example git commit will supposedly pick all the tracked files in the current directory and use their content to create a new commit; if there are modified files in other directories in the work tree (no matter whether staged or not), they will be ignored.

So, yes, in a sense, running git commit . in a subdirectory of the work tree is like committing only the changes in that directory, but you should clearly understand that this is vastly different from Subversion where committing a subdirectory actually performs a kind of server-side merge -- such a commit will succeed if there's no changed files in that subdirectory made after our base revision. In Git, the resulting commit will be the whole state of the project, as usually.

Hence, as I've said, whether git commit . is a real use case or not depends on your preference. I, for one, do not like such shortcuts and prefer to explicitly git add what I need, even if these changes are localized to a subdirectory, review what I'm about to commit (using git diff --staged) and then commit.

answer Mar 6, 2014 by anonymous
Similar Questions
+2 votes

How can I add a file later to a commit? I created a new branch and submitted a commit with 2 files.

I observed, that one more file should have been submitted with this commit, so I would like to add a file to an earlier commit.

Any solution for this?

+2 votes

Can someone help me on how to delete an intermediate commit?

0 votes

I want to retrieve the commit history of a given file.What command should I issue? I expect the command like below.

D:GitTest> git show --commit-history test.txt
8194aaa
c419234
...
0 votes

I want to show commit related information by the command below.By this, committed files are shown, but names only, off course.But in addition to this, I want to show commit file types (New, Edited, and Deleted).What argument should I use in the command?
git --no-pager show --format=%h%n%an%n%ai%n%s --name-only

+1 vote

I did a series of commits and now I find one of my commit (not the topmost one) has an incorrect commit message. How can I change that specific one? I believe "git commit --amend" works only for the last commit.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...