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

  • 本文关键字:其他 保留 GitHub git git-push
  • 更新时间 :
  • 英文 :


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

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 存储库中。
现在如何仅将test1test4test5test7推送到我的 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 内容。

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

例如,一个.gitkeep空文件。

如果它们不为空,则 agit add test1 test4 test5 test7就足够了。
或:

  • .gitginore中添加其他文件夹(您不想添加)。

    test10/
    
  • 然后你可以git add .(不需要*),提交和推送。

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

避免使用git add *,因为"*"是由外壳解释的。

相关内容

最新更新