1

I just want to push file without edit gitignore

i.e i added /vendor in gitignore. but i need to push one file which is available in /vendor/test.txt

i don't need to push other file except test.txt how can i do that any idea please share

Dhaval Vaghela
  • 440
  • 4
  • 20
  • `/vendor` -> `/vendor/*` – user4003407 Jan 12 '18 at 12:27
  • You can just drop this line in .gitignore, add the file, then checkout the original .gitignore. This file is used to choose which previously untracked files should be ignored, but the files which are already tracked are not affected by it. – raina77ow Jan 12 '18 at 12:32
  • Possible duplicate of [How do I push files specified in .gitignore?](https://stackoverflow.com/questions/11788229/how-do-i-push-files-specified-in-gitignore) – tkruse Jan 12 '18 at 13:26
  • 1
    Note that Git doesn't push *files*; `git push` pushes *commits*. Commits *have* files but the thing you're working with is not a file but rather a commit (or many commits). This eventually matters quite a lot, so it's wise to avoid using the phrase "push a file". – torek Jan 12 '18 at 16:05

2 Answers2

3

See man git-add:

   -f, --force
       Allow adding otherwise ignored files.

So run this

git add --force vendor/test.txt
Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
  • 1
    so i need to add git add --force vendor/test.txt git commit -m '' git push origin master am i right ? – Dhaval Vaghela Jan 12 '18 at 12:33
  • Correct. Give this a try. You can always go back with 'git reset' – Dimitri Dewaele Jan 12 '18 at 12:40
  • 1
    .gitignore doesn't care about pushing, it is used when adding files. If you manage to add a file or edit the .gitignore file to ignore an already added file, git still tracks that file just as it tracks any other file it tracks. – Lasse V. Karlsen Jan 12 '18 at 13:45
0

In you .gitignore file

/vendor
!/vendor/test.txt
Melebius
  • 6,183
  • 4
  • 39
  • 52
Jerry Chen
  • 715
  • 7
  • 21
  • i already do that , when i checked git status then it will not showing test.txt – Dhaval Vaghela Jan 12 '18 at 12:23
  • *It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.* [Documentation](https://www.git-scm.com/docs/gitignore#_pattern_format) – user4003407 Jan 12 '18 at 12:27