As mentioned in the answer you’ve got before, you are not able to commit the whole project as you said. You are only able to commit changes that haven’t been recorded yet.
Bearing that in mind, if you see that there are no files in the “commit changes” screen there is no need to panic. The changes to your files are safe and sound, they have been recorded by git and you won’t lose those changes.
Nonetheless, disagree with the previous answer. From what I understood, you have made few changes to the project but now you can’t locate them. As you said in your question - you recall pressing on something by accident and now the files are “gone” from the list of files you are able to commit.
In that case, let’s try to figure out together where those changes can be.
There are number of possibilities:
First, let’s cover the way git is recording changes -
Git is tracking your files in order to see if there were any changes to the files. If so, git will notice the changes and you will be able to commit them. All tracked files start as “unmodified”. Then, when you edit them they are marked as “modified”.
When you chose to commit the files, git will prepare them for the commit, asking you which file you wish to commit and those will be marked as “staged”.
After a commit is done, all the files are back to the “unmodified” status.
You can read the explanation from the “Git Basics” book for further information:
Remember that each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else – any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because Git just checked them out and you haven’t edited anything.
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats.
By rule, Android Studio will mark the files in your directory according to their status in git.
If you see that some of the filenames in your repository appear in red, you can:
Right Click => Git => Add and they will be tracked by git and you will be able to see them when you are trying to commit.
Gitignore list will let you specify intentionally untracked files to ignore.
The ignore list is basically a file containing the locations of the files in your working directory that you would like git to untrack. This list will prevent untracked files from being added to the set of files tracked by git (bearing in mind that git will continue to track any files that are already being tracked).
If this is your case, adding a file to the gitignore list will make it “disappear” from the list of files you are able to commit.
So, in order to get it back and commit it again, you will need to remove it from the gitignore list.
In order to do that, you will need to type
git add -A command into the git command line. This command will staged all files in your directory (new, modified, deleted) and it will solve your problem.
In addition, you should take a look at the Ignored Files list which is configured on Android Studio and make sure that files you are looking to commit aren’t there.
To access the Ignored Files list, go to
Project => Settings => Version Control => Ignored Files (Windows and Linux) or
Android Studio menu => Preferences => Version Control => Ignored Files (MacOS). In there, you will able to remove it from the “ignored files” list.
From the “Git Basics” book:
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.
You might have stashed your files, and now they appear to be unmodified and you aren’t able to commit them.
In order to un-stash them (clicking on the main folder of your project):
Right Click => Git => Repository => UnStash Changes… , then select the most recent stash from the list and click on
If you see nothing on the list, or if the list does not contain the latest changes you have made, then this is not your case.
The last possible option is that you have already committed the changes but you haven’t pushed them to your remote repository so you don’t see them on the cloud/other computers.
As mentioned above, the git commit command will record changes to your file, but the most important thing in here is that is will be recorded on your local repository.
In order to update the remote repository as well you will need to push those changes too, using the git push command.
Android Studio offers two changes: commit changes and commit and push changes.
You might have chosen to commit the changes, and in that case:
Here is a nice picture from Oliver Steele, that explains the git model and the commands:
In order to solve this, all you have to do is to push the changes to your remote repository by:
Right click => Git => Repository => Push. That simple.
Here are some helpful links:
Hope my answer has helped you in solving your problem :)