最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

git push - How do I ignore files in a directory in Git which are already staged? - Stack Overflow

programmeradmin2浏览0评论

I've a local directory: Networking (where I did git init).

  1. I added another directory: Aruba (with *.pdf files in it) inside directory: Networking
  2. Made some changes in the already existing files in the directory: Networking
  3. Added .gitignore file with just two lines in it (Line #1 *.pdf, Line #2 *.mp4)
  4. I did git add ., git commit -m 'updated aruba_controller.md' and then finally git push.
  5. It still pushes my pdf and mp4 files. Why?
  6. Deleted the directory Aruba and after some google then applied the command: git rm --cached -r ~/Documents/Networking/Aruba/ and now I'm getting error: fatal: pathspec '/home/UserName/Documents/Networking/Aruba/' did not match any files
  7. Recovered the directory Aruba from Trash, ran the command in #6, same result.

I'm on ubuntu 24.04. What I can do to fix it? I don't want my pdf and training videos to get uploaded in GitHub. Thanks

I've a local directory: Networking (where I did git init).

  1. I added another directory: Aruba (with *.pdf files in it) inside directory: Networking
  2. Made some changes in the already existing files in the directory: Networking
  3. Added .gitignore file with just two lines in it (Line #1 *.pdf, Line #2 *.mp4)
  4. I did git add ., git commit -m 'updated aruba_controller.md' and then finally git push.
  5. It still pushes my pdf and mp4 files. Why?
  6. Deleted the directory Aruba and after some google then applied the command: git rm --cached -r ~/Documents/Networking/Aruba/ and now I'm getting error: fatal: pathspec '/home/UserName/Documents/Networking/Aruba/' did not match any files
  7. Recovered the directory Aruba from Trash, ran the command in #6, same result.

I'm on ubuntu 24.04. What I can do to fix it? I don't want my pdf and training videos to get uploaded in GitHub. Thanks

Share Improve this question edited Mar 30 at 20:48 GS6651 asked Mar 30 at 20:46 GS6651GS6651 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Here's a few things you can check:

  1. Make sure your gitignore file is on the root of your project.

  2. Look at the documentation of git, rm --cached -->

    Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

From what it looks like, it might still be pushing your files because your gitignore file is not in the right spot or you might not be using the rm --cached command correctly. You can use git diff or git diff --cached to investigate further.

However, I would use something more visual to better see what's going on in the staging area before you commit. Using the Git Pull Requests and/or Source Control area in VSCode can be your favorite friend in determining why these files are being pushed still. Let me know if that helps!:)

发布评论

评论列表(0)

  1. 暂无评论