git commit changes not staged for commit Message

Posted on

This is an article where the commit process is stumbled upon a message stated as in the title of this article. When performing an operation including moving folders, files and even deleting several folders and files, there are operations which is actually doesn’t included into the staging area in the git commit execution as shown below :

git commit -m "Modifying Folder's Structure"

Below is the execution of the command :

user@hostname:/home/user/source$ git commit -m "Source Modification"
[master 620729e] Source Modification
13 files changed, 11 insertions(+)
create mode 100644 app/Application.php
...
user@hostname:/home/user/source$

After committing the already changed files, push it to the Repository Git :

user@hostname:/home/user/source$ git push --set-upstream application
Username for 'http://app.repository.com': user
Password for 'http://[email protected]':
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 1.28 KiB | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
To http://app.repository.com/gitlab/user/application.git
50e9f83..620729e master -> master
Branch master set up to track remote branch master from application.
user@hostname:/home/user/source$ git-ftp push
fatal: Dirty repository: Having uncommitted changes. Exiting...
user@hostname:/home/user/source$ git-ftp push
fatal: Dirty repository: Having uncommitted changes. Exiting...
user@hostname:/home/user/source$ git commit -m "Source Modification"
On branch master
Your branch is up-to-date with 'application/master'.
Changes not staged for commit:
deleted: resources/views/sidebar.blade.php
deleted: resources/views/test/index.blade.php
deleted: resources/views/test/edit.blade.php
deleted: resources/views/test/show.blade.php
deleted: resources/views/test/update.blade.php
no changes added to commit
user@hostname:/home/user/source$

There are some error message shown in the above output of commit process : “fatal: Dirty repository: Having uncommitted changes.”. The changes which is an addition and modification of folders and files are being processed but not the deletion process. It is also shown in the output above : “Change not stated for commit”, it consist of files which are deleted. So, there are nothing in the staging area which involving the deletion process are being committed.

Try to push it again :

user@hostname:/home/user/source$ git push --set-upstream application
Username for 'http://app.repository.com': user
Password for 'http://[email protected]':
Branch master set up to track remote branch master from application.
Everything up-to-date
user@hostname:/home/user/source$

Execute the command again for checking the status :

user@hostname:/home/user/source$ git status
On branch master
Your branch is up-to-date with 'application/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: resources/views/sidebar.blade.php
deleted: resources/views/test/index.blade.php
deleted: resources/views/test/edit.blade.php
deleted: resources/views/test/show.blade.php
deleted: resources/views/test/update.blade.php

So, the modification in the local by deleting several files or folders is ignored and it is not staged for commit process. To solve this problem, try to add another parameter in order to include the delete operation into the staging area for further commit as shown below :

user@hostname:/home/user/source$ git add -u

After adding the operations which is being implemented with the additional parameter -u, execute the ‘git commit’ command for committing the delete operation as shown in the following command execution :

user@hostname:/home/user/source$ git commit -m "Modifying Folder Structure"
[master 34b644c] Modifying Folder Structure
20 files changed, 5 deletions(-)
deleted: resources/views/sidebar.blade.php
deleted: resources/views/test/index.blade.php
deleted: resources/views/test/edit.blade.php
deleted: resources/views/test/show.blade.php
deleted: resources/views/test/update.blade.php

After done committing the source code, to make the changes available in the remote Git Repository, the following command is executed :

user@hostname:/home/user/source$ git push --set-upstream application
Username for 'http://app.repository.com': user
Password for 'http://[email protected]':
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 241 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To http://app.repository.com/gitlab/user/application.git
620729e..34b644c master -> master
Branch master set up to track remote branch master from application.
user@hostname/home/user/source$

Since the repository is also set not only to a remote Git Repository but it also set into another location which is actually an FTP Server initiated with Git Repository, the command which is needed to push the modification is shown below :

user@hostname/home/user/source$ git-ftp push
There are 33 files to sync:
[1 of 6] Buffered for upload 'app/'.
[2 of 6] Buffered for upload 'app/Application.php'.
[3 of 6] Buffered for upload 'app/DatabaseInstance.php'.
[4 of 6] Buffered for delete 'app/Database.php'.
[5 of 6] Buffered for delete 'app/Employee.php'.
[6 of 6] Buffered for delete 'app/OperatingSystem.php'.
...
Uploading ...
Deleting ...
Last deployment changed to 34b644c450e082929f9b7e59ba51add98455194c.
user@hostname:/home/user/source$

The conclusion is on the premise for using ‘git add -u’ solved the problem above which preventing someone from committing delete operation on the Git Repository. Below is the information detail on the ‘-u’ parameter passed to the git add command :

-u, --update
Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.
If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories).

Based on the above context, no files were added after all. It just erasing several files and folders. So, in order to do that, based on the problem faced, using ‘-u’ is an alternative for committing the delete operation on the remote Git Repository.

2 thoughts on “git commit changes not staged for commit Message

Leave a Reply