如何将部分目录推送到 GitHub 而将其他目录保留在本地?

How to push part of directories into GitHub and remain others locally?

我的本地目录test中有很多文件。

ls  test
test1   test2   test3  test4 test5 tes6 test7 

推送测试中的所有文件

cd test
sudo git init
git add *
git commit -am  "push"
git push -f  origin master

file1file7 的所有文件都推送到我的 github 存储库中。
现在如何将 test1 test4 test5 test7 推送到我的 github 存储库?

这是我的 wordpress 目录。

ls /var/www/html/wp
index.php        wp-blog-header.php    wp-includes        wp-signup.php
license.txt      wp-comments-post.php  wp-links-opml.php  wp-trackback.php
readme.html      wp-config.php         wp-load.php        xmlrpc.php
wc               wp-config-sample.php  wp-login.php
wp-activate.php  wp-content            wp-mail.php
wp-admin         wp-cron.php           wp-settings.php

推送所有目录而不是 wp-content。

如果这些文件夹是空的,您需要在其中添加一个文件(任何文件)。

例如,一个 .gitkeep 空文件。

如果不为空,一个git add test1 test4 test5 test7就够了。
或者:

  • .gitginore.

    中添加其他文件夹(您不想添加)
    test10/
    
  • 然后就可以git add .(不需要*),提交并推送。

这将添加除您不需要的文件夹之外的所有内容。

避免 git add *,因为 '*' 由 shell 解释。