-1

I am trying to commit a file called "index.html" using git but git is committing just a empty file without any insertions even after I make sure the file have changes, this is the terminal command that I've run

PS C:\Users\m00n\Desktop\projects> mkdir Git-project

PS C:\Users\m00n\Desktop\projects> cd Git-project
PS C:\Users\m00n\Desktop\projects\Git-project> git init
Initialized empty Git repository in C:/Users/m00n/Desktop/projects/Git-project/.git/
PS C:\Users\m00n\Desktop\projects\Git-project> git status  
No commits yet

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

nothing added to commit but untracked files present (use "git add" to track)
PS C:\Users\m00n\Desktop\projects\Git-project> git add index.html
On branch master

No commits yet

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

PS C:\Users\m00n\Desktop\projects\Git-project> git commit -m "committing index.html"
[master (root-commit) 0a7e832] committing index.html
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html

first creating directory called "Git-project", then entering it and initializing a git repository, then creating a file called "index.html" from the file explorar, then writing some code to the file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>search</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <header>
        <a id="searchlink" href="index.html" class="active">Text search</a>
        <a id="imagelink" href="image.html">Images search</a>
        <a id="advansedlink" href="advansed.html">Advansed search</a>
    </header>
    <form action="https://www.google.com/search">
        <div>
            <input type="text" name="q" id="textInput">
        </div>
        <input type="submit" value="Google Search" id="submitBtn">
    </form>
</body>
</html>

for example, then making sure the file exist by running "git status", then staging the file by running "git add index.html" and running "git status" again to make sure the file is there and is ready to by committed, and finaly committing the file, the problem is in the commit message there is 1 file but 0 insertions, which means git has committed just an empty file, I've tried to make a repository on github and then connecting to it and running the code, but the problem is the same, after I push all the commits to github, I see just an empty file, I don't know why?

2
  • You diligently showed the output of git status for the first commit, but omitted it for the second commit and only described what you saw. Show it literally! Commented Apr 21, 2024 at 7:03
  • 1
    I think you either didn't save the file or were working on a file in another directory. Commented Apr 22, 2024 at 7:00

1 Answer 1

0

I guess you need to check the order in which you made changes to the file and you made a commit.

For example,

  1. First you did mkdir Git-project and cd Git-project and finally git init
  2. Now re-iterate and check if you just created a new file named index.html and directly added and made a commit. ⚠️

Check and compare the commands in both the scenarios.

add content and commit add empty file and commit

If you create an empty file and commit then there will be no insertions but I guess you created an empty file, made a commit and tried to add content to index.html (correct if i am wrong).

Sign up to request clarification or add additional context in comments.

4 Comments

No, I am sure that I code the file before staging it, and then committing it.
I don't know why, but the bug has disappeared suddenly, I have been stuck in this bug for nearly three days, so I asked this question then get to work in css file outside git that's when I noticed there is an "M" next to the file name which stands for "modified", this didn't appear before, so I try to commit the file and it work, later I try to add another file, but the same problem appear so I try to close the file, thats when a notification pops out saying "do you want to save the changes" so I clicked save, and the same thing happened, the file said "modified", and I could submit it.
the main problem right now is "how to commit a file without having to close it frequently " I hope you know the answer, but I will give you accepted any way.
What do you mean "how to commit a file without having to close it frequently" ? Can you elaborate ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.