3

Suppose I have a folder

application/uploads

EDIT

application/uploads/{a}/{b}/{c}/{d}/{e}/{f}/{g}/abcdefghijklmnopqrstuvwxyz

{a},{b},{c},{d},{e},{f},{g} - are hash keys, any alpha-numeric characters are possible

abcdefghijklmnopqrstuvwxyz - is a hashed filename

I don't want git to track it neither on development machines nor on production server, so it is added to a .gitignore file.

Suppose now I've created a branch "Backups" on the production server where I want to store the state of the project at different moments of time.

To do that I need to 'add' and 'commit' all files of a project including those which are under .gitignore

Note: Changing .gitignore is a bad idea in general because

  1. It might cause problems when pulling changes from develment branches

  2. In a heavily loaded and recently changing project it will be a problem to checkout other branch because of new untracked files that are added each second right after you finished adding and commiting the previous ones

  3. etc...

So the question: How do I force git to 'add' files that are under .gitignore ad then 'commit' them without actually changing .gitignore?

2 Answers 2

7

From the git-add manpage:

   -f, --force
       Allow adding otherwise ignored files.
Sign up to request clarification or add additional context in comments.

6 Comments

unfortunately it doesn't work I've used git add --force root/uploads and git add --force root/uploads/.
git status gives # On branch Backups nothing to commit (working directory clean)
@Denis: You can't just specify the directories. You need to specify the files to force-add. e.g., git add -f root/uploads/*.
@Denis Then add the files individually, or use find -type f -exec git add -f "{}" \;. You cannot add directories to Git, only files. If your root/uploads contains only empty folders, you will need to place a .keep or some kind of placeholder file in the deepest folder. You cannot add empty folders to git.
@meagar: Instead of \;, use +. This runs git add far fewer times. (; => once per file; + => once per as-many-files-as-will-fit-in-the-command-line.)
|
1

.gitignore allows not only to ignore but also to re-add, it's the exclamation mark:

!add-this-dir/file/whatever

You will find this properly documented here, if you're in shell type git help gitignore.

Comments

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.