Can't Add File to Git Repository But Can Change/Commit

can't add file to git repository but can change / commit

error: insufficient permission for adding an object to repository database .git/objects

That is your problem. For some reason or another, Git is having trouble writing to .git/objects - typically this means it is owned by another user and doesn't have the proper permissions.

Try seeing what permissions the folder currently has by running ls -l .git/objects. Then, you can chmod or chown (or both) as necessary.

I used git add but I can't commit it

i had the same issue. the problem is with the git index if i remember right.
close all git service or program relate and delete the .git folder from the repository. and add the origin again to the folder. it should show you the file that need to be stage. if it didnt help you try go to the origin repo and create this file and delete it.

i hope it help.

Git won't add modified file

I think maybe Jubobs' comment is correct. Is your "file" a submodule?

This line (commit or discard the untracked or modified content in submodules) should not appear for normal files.

Here is what I get from git status:

$ git status
On branch master
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: README.txt

no changes added to commit (use "git add" and/or "git commit -a")

You will not see (commit or discard the untracked or modified content in submodules) and (modified content) after my README.txt

So you may need to do what git recommended, work on the content in submodules.

Edit: Previously I thought the "git add ." could solve the issue but now I think it could not.

Can't commit changes while changing the code in github

It means you are not a collaborator in the pamekasancode/Code-Forces-Algorithm: you can not contribute directly to the main/master branch of that repository.

You should be able to commit if you select the second option

"Create a new branch for this commit and start a pull request".

See as illustration "How to make your first contribution in GitHub without using Command line" from Haimantika Mitra

make new pr

git: Can't add files to github

You need to set your local repo to push upstream to your github repo.
from: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line

Your next steps would be:

# create repo via github ui or github cli

# add github as the origin
git remote add origin remote_repository_URL

# push changes to repo
git push origin master

Git add and commit is not adding files

Let's clarify a few concepts of git:

  1. Your local directory is a git repository. All git commands interact with the local repository in some way. Some commands also interact with a remote repository

  2. git add . will all files in the current directory to the staging area of your local repository. Whenever you do this, git will always add the files because this is how git works. Note that "adding" files only stages them for the next git commit.

  3. git commit creates a commit in your local git repository with the files that you have previously added to the staging area. Again, this command will always do this. In fact, the output from git ls-files in your post proves that all of your files have been added and committed to your local repository.

  4. Your local repo can be connected to remote repo on GitHub or any other sever running git. If you do git clone, your local repo will have a remote named origin which points to the repo which you cloned. If you do git init instead, you can use git remote add to add a remote with whatever name you wish.

  5. Once you have a remote repo configured in your local repo, you can use git push to push commits from your local repo to the remote one. Likewise, git pull will pull commits from the remote to your local repo.

Can't add a file to git, seriously

Let's talk about what git says when you talk to it. First, here's a folder with some files in it:

$ ls
a.txt b.txt

Now I'll try to add a.txt to the staging area:

$ git add a.txt
$

Hmm, git didn't say anything. That's just like what you reported:

Running git add init.el does not produce any output

Darn. Why isn't it being added? Okay, let's try something else:

$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: b.txt

Hmm, it didn't list a.txt. I'm getting worried! Okay, let's try a different way:

$ git diff --cached
diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+hello

Hmm, again it didn't mention a.txt. That's just like what you reported:

the file is still missing from the staging area (I have checked this with git status, git diff --cached

You also said:

The file (or a pattern matching it) does not appear when I run git ls-files --others -i --exclude-standard

OK, let me try that too:

$ git ls-files --others -i --exclude-standard
$

Nothing! Gosh, this is terrible. Why isn't a.txt being added to the staging area?

Because it's already in the staging area. The problem here is not that a.txt is not in the staging area; it's a misunderstanding of what the staging area is — possibly of what git itself is.

Here's the thing to remember:

  • Every commit contains all the files.

  • By default, every new commit contains all the same files as the previous commit. (The only differences will be files you have changed.)

  • By default, the staging area contains all the files in the last commit.

  • When you ask questions like git status or git diff, git only tells you what is new and different. It doesn't report what exists.

So that explains the mystery. Before all of this started, I already added and committed a.txt. So it is already in the staging area and it is already in the last commit.

So when I say git add a.txt, git says to itself: "Yep, well, a.txt is already in the staging area, and it hasn't changed, so nothing new here, move along, folks, move along" — and it doesn't reply.

And when I say git diff --cached, git doesn't mention a.txt because diff means "difference", and a.txt in the staging area is not different from a.txt in the last commit.

But none of that means that a.txt is not in the last commit or that it is not in the staging area. On the contrary, it means exactly the opposite. It means that it is in both of those places.

Now let's talk about lists.

Let's say we want to know what files are in the staging area. That's what git ls-files is for, plain and simple:

$ git ls-files
a.txt
b.txt

Look, there it is! a.txt is there after all! Okay, let's say we want to know what's in the most recent commit. Remember, what's in the most recent commit is also what was in the previous commit, and the commit before that, and the commit before that, except for any changes we may have performed each time. Every commit contains all the files, by default. So if a.txt has ever been committed, it is sufficient to see if it is in the latest commit. And here's how to do that:

$ git ls-tree --name-only HEAD
a.txt

There it is again!

So you see, a.txt was not failing to be added after all. It's just that I didn't understand what git was telling me.

Finally, you also say

Trying to commit, push and double check what is going on in Github confirms that the file has not been added

Well, I can't explain that one. But I can't look over your shoulder and see what you're doing at GitHub — and GitHub is hard to use. Maybe the problem is just one of not knowing how to look. If you are on a branch locally and you commit and push, and you then go to GitHub and hunt for a file, you might not find it, because GitHub by default doesn't show you the branch you were working on; it shows master (or main).

So here's my guess as to what's going on: You are on a branch locally, and you already added-and-committed init.el, perhaps quite a while ago, and you have not changed it since then. That, as I think I've demonstrated, would explain the phenomena you have described in your question.

git add . - still nothing to commit with new files

Your commands look correct (I've done them many times that way).

First try

git add --all

and then try git status. I don't think that will solve it, but worth trying next.

Next try looking at your .gitignore file, if you have one (in the top level where you did git init).

cat .gitignore

Remove any listings there that are causing your files to be ignored. For example is there an entry with just *?

Next try:

git add --force

and then try git status.

If none of those work, I notice that your output from git init says "reinitialized" rather than "initialized", so something may have gotten messed up. If you've just initialized it and don't mind losing history, start over by removing the .git dir:

rm -rf .git

And then reexecute your same commands above. If that doesn't work, some more information about your setup will be required. For example, you might have a global .gitignore file: ~/.gitignore_global that needs to edited (or removed if you don't want it).



Related Topics



Leave a reply



Submit