Unable to Git-add with force
Asked Answered
W

7

16

I get git-status at ~/bin:

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

I run

git add --force screen/dev/

I get the same git-status as before. I add each file in the folder independently, but I get the same git-status.

There is no .git in screen/dev/. The folder seems not to be a sumbodule.

How can you add a folder and its content with force to my git at ~/bin?

Warily answered 15/7, 2009 at 0:45 Comment(3)
Can you reproduce this with a fresh Git repository, starting from "git init"?Uplift
@Greg: I cannot reproduce the problem with a fresh Git repository, although I keep exactly the same names in the file structure. --- This suggests me that there must be some file in my repo which manipulates the folder screen/devLasseter
I experienced the same problem on Windows. Turns out that I was adding the file "foobar.txt" when the filename was "Foobar.txt". Windows is case insensitive but Git still behaves as if it's running on Linux, so it treats files as case sensitive.Goshawk
W
9

The problem can be solved by renaming the folder and adding the folder with a new name to Git.

This suggests me that there must be some file manipulating the folder name dev.

Warily answered 15/7, 2009 at 22:6 Comment(0)
T
10

You should not need '--force' or '-f' option: see git add:

-f
--force:

Allow adding otherwise ignored files.

In your case, you may not want to add all files, included ignored files under screen/dev directory.

 git add screen/dev

should be enough (without options or ending '/')

Transposal answered 15/7, 2009 at 4:13 Comment(3)
The same problem occurs also without /.Lasseter
The title of the post is "with force" and the user said they've used --force already.Zendah
@GuillermoPrandi I understand. I thought (10 years ago) that --force was not needed in this case.Transposal
W
9

The problem can be solved by renaming the folder and adding the folder with a new name to Git.

This suggests me that there must be some file manipulating the folder name dev.

Warily answered 15/7, 2009 at 22:6 Comment(0)
C
6

Is that a typo on cut paste?

If not, it should be

git add --force screen/dev
Caterer answered 15/7, 2009 at 0:55 Comment(0)
R
3

Try doing:

git add -A .

Also, if you have a .gitignore file it's also possible that you are unintentionally ignoring something (ie: possibly the files you are trying to add).

Rotifer answered 15/7, 2009 at 4:19 Comment(2)
The same problem occurs also after running your command. I do not have the folder at the .gitignore -files.Lasseter
This command doesn't make sense. -A and . do the same thing. No reason to combine both. See here: #573049Kayo
K
3

If nothing works...

  • Move the stubborn directory to a temp location outside the repo
  • Remove any remaining traces of the stubborn directory in the repo
  • Push and make sure that local is synced with remote
  • Move the stubborn directory from the temp location back to the repo (You don't have to rename)
  • git add -A
  • Commit and push
Kayo answered 26/9, 2017 at 14:31 Comment(0)
I
0

I've also found that you have to have at least a file in that dir in order to be picked up by git. git add screen/dev won't work if there are no files inside.

Innerdirected answered 14/5, 2018 at 8:59 Comment(0)
G
-1

Just git add .

Take a break Have a KitKat Make a cup of coffee

and when you come back after a while it should be done

Gensmer answered 4/11, 2022 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.