Reputation: 11
I'm a new user trying to commit and push my first .md
file. I screwed up and tried to commit without a message, giving me a fatal error and landing the file in both the staged and unstaged areas.
Online advice said to remove it. I tried rm and got the same fatal error message. Other online help said "physically remove" the file, and not being sure what that meant I deleted it and emptied the trash.
I don't need the file. I"m happy to start over. I Just need to clear the mess and start again.
I tried to reset, I tried rm cached.
Here's what shows in git gui, in the yellow field in the northeast quadrant:
Staged for commit, missing <file>
deleted file mode 100644
@@ -1 +0,0 @@
-## This is a markdown file
\ No newline at end of file
git status says on branch master, initial commit, changes to be committed: (use "git rm --cached to unstage), then it lists the deleted file as a new file in green, then changes not staged for commit, a new suggesting to add/rm or checkout (all tried), and it lists the deleted file in red.
The error message I get is
fatal, unable to create project/.git/index.lock: file exists.
Then it says that if no other git process is currently running, it's likely that a git process crashed in this repo earlier, and it suggests I physically remove the file.
I'm using git bash as per my Coursera instructions, and it doesn't let me copy text the way I'm used to. I also have git gui, and I'm checking that against the git bash output. It's all new to me. I'm sure I missed some parentheses and/or quotation marks as I tried to type what I saw in the error messages.
I don't know what a shell is. I'm using Windows 7.
I don't have any other files in this repo and could start over. Not sure how to delete a repo but I can look it up if that's the fix.
Upvotes: 1
Views: 330
Reputation: 11
The error message "Unable to create 'C:/users/shannon/.git/index.lock': File exists" was related to the dirty file Cupcake described this way: "So it looks like your biggest issue was the fact that it looks like git ended up crashing and left you with a dirty index.lock file that needed to be cleaned up."
The fix was rm -f ./.git/index.lock. That alone allowed me to resolve the other issues.
Upvotes: 0
Reputation:
So it looks like your biggest issue was the fact that it looks like git ended up
crashing and left you with a dirty index.lock
file that needed to be cleaned
up. Since you didn't have anything else in the repository, you can either
delete that file, located under the .git
folder of your project, or you can
just remove the entire .git
folder, as suggested in merlin's answer.
However, assuming that you didn't have that index.lock
problem, here is how
you can fix your issue if it happens again. I've replicated the steps you
described, and I ended up with this:
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.md
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: readme.md
You can either commit your readme file from here (since it's already staged), or you can choose to check it out into your working copy again. The working copy doesn't really matter at this point, because all that matters for a commit is what's in the staging area.
Given the above, you can do the following in any order...no matter which order you choose, you'll get the same result:
git commit -m "Your commit message"
git checkout -- readme.md
Here is some un-related but useful instructions for copying and pasting from Git Bash, since you were having trouble with it earlier.
Right-click on your Git Bash window at the top, then select Properties
.
Under Options
select both QuickEdit
and Insert
modes (I'm not actually sure if you need both, but I have them both on, and everything works fine for me):
Hold left-mouse button and select the area that you want to copy:
Right-click to copy the selected area to your clipboard. You can now paste it wherever you want:
$ gs On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.md
Upvotes: 0
Reputation: 75629
You mentioned that this is your first commit. If you want to just clean up completely, the easiest way to do it is to cd
to your directory (inside git bash
), remove the .git
directory, and start running your instructions from the start.
Warning: This will delete your entire local repository, so make sure you truly do not need it.
rm -rf .git
If you are on a purely local repository, and you want to re-initialize, you can do:
git init .
git add MyFile.md
git commit -m "Commit Message"
Upvotes: 1