Git 'nothing to commit, working tree clean'

0

I got a laravel project by means of git clone , I made a new branch so as not to modify the original, but at the time of giving git commit it marks me:

nothing to commit

I have checked and I am in the correct folder, why can not I commit?

    
asked by Paloma Alvarado 05.07.2017 в 17:17
source

2 answers

1

I think what you are not understanding well on the issue of the branches in Git is that the fact of creating a new branch is not sufficient reason in itself to consider that there is a change in the project. Maybe with an example you can better understand it. Let's try a "test" project with a single file called "file.txt":

$ mkdir test
$ cd test/
$ git init
Initialized empty Git repository in /home/cesar/test/.git/
$ echo "¡No modificar este archivo en el branch master!" > archivo.txt
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    archivo.txt

nothing added to commit but untracked files present (use "git add" to track)
$ cat archivo.txt 
¡No modificar este archivo en el branch master!
$ git add .
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   archivo.txt

$ git commit -m "Primer release"
[master (root-commit) 21074dd] Primer release
 1 file changed, 1 insertion(+)
 create mode 100644 archivo.txt
$ git branch 
* master

Okay, we only have the branch master for now. Imagine that this is my project and you clone it from a remote repository (GitHub, Bitbucket, etc.):

$ git clone .... 

You decide to create a new branch so as not to modify the master branch:

$ git checkout -b paloma
Switched to a new branch 'paloma'
$ git status
On branch paloma
nothing to commit, working tree clean

As you can see, your "working tree" is clean (because you have not modified or added anything new) and, therefore, you will not be able to commit:

$ git commit -m "Mi branch"
On branch paloma
nothing to commit, working tree clean

But, how about modifying the file?:

$ echo " ¡Jódete jefe!" >> archivo.txt
$ git status
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   archivo.txt

no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
$ git commit -m "Que se joda el jefe, he modificado el archivo en mi propio branch"
[paloma 81a5fa3] Que se joda el jefe, he modificado el archivo en mi propio branch
 1 file changed, 1 insertion(+)
$ git branch
  master
* paloma

Now yes, you can push and create your branch with your changes in the repository you have previously cloned. I hope it has helped you.

    
answered by 05.07.2017 / 18:26
source
0

This is because you must first add the files to commit.

To see the status of git usa:

git status

To add ALL the "untracked" files you use :

git add .

YES, git then the word add and then . (period) this will add absolutely everything you have modified, added or deleted.

To commit :

git commit -m "ESTO ES UN COMENTARIO ENTRE COMILLAS DOBLES"
    
answered by 05.07.2017 в 18:04