简体   繁体   English

在本地存储库中提交多个文件(包括我需要推送的文件)后,如何将特定文件推送到 GitLab?

[英]How can I push specific files to GitLab after I have committed multiple files (including those which I need to push) in a local repository?

I have already committed the following files in the local Git repository:我已经在本地 Git 存储库中提交了以下文件:

  • dir1/file1目录 1/文件 1
  • dir1/file2目录 1/文件 2
  • dir2/file3目录 2/文件 3
  • dir2/file4目录 2/文件 4

Now I want to push only two files out of four files, ie, dir1/file1 and dir2/fil4 to GitLab.现在我只想将四个文件中的两个文件,即dir1/file1dir2/fil4 推送到 GitLab。 Is it possible?是否可以? If yes, what is the appropriate Git command?如果是,那么合适的 Git 命令是什么?

I think this might be a duplicate of How can I push a specific commit to a remote, and not previous commits?我认为这可能是如何将特定提交推送到远程而不是以前的提交的副本 ? ?

I'll warn you that the rebase command that answer mentions can be a bit confusing.我会警告你,回答提到的rebase命令可能有点混乱。

Depending on why you don't want to push all of the files:取决于您不想推送所有文件的原因:

  • If you only meant to commit 2 of the 4 in the first place you can use git reset --soft <the-commit-hash-before-you-commited> .如果您一开始只想提交 4 个中的 2 个,则可以使用git reset --soft <the-commit-hash-before-you-commited> Then you can re-add only the files you want to commit.然后,您可以仅重新添加要提交的文件。 BUT if you have already pushed some of those commits to remote then you have to do a --force push, which you may not have permission to do.但是,如果您已经将其中一些提交推送到远程,那么您必须执行--force推送,您可能没有权限这样做。
  • If you never wanted those files to be committed at all, you should add them to the .gitignore so they don't come up again.如果您根本不想提交这些文件,则应该将它们添加到.gitignore以免它们再次出现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算提交后将推送的文件大小? - How can I calculate the size of files which will push after commit? 从GitHub删除所有本地文件并下载存储库后,我不能使用git push - After deleting all local files and downloaded repository from GitHub, I can't use git push 如何将本地回购更改推送到远程回购,而远程已经更新了我没有的文件? - How can I push the local repo changes to remote repo and remote has already updated files which I don't have? 如果检测到本地修改(包括未跟踪文件),如何防止git push? - How can I prevent git push if local modifications are detected (including untracked files)? 如何仅对 Gitlab CI 中已更改的文件进行掌舵推送? - How to do a helm push of only those files which have changed in Gitlab CI? 如何使用 git push 将本地文件推送到远程 github 存储库? - How do I use git push to push local files to a remote github repository? 为什么不能推送到GitLab存储库? - Why can't I push to a GitLab repository? 将所有文件推送到我的 github 后如何修复 git 提交的身份不明的用户 - How to fix git committed unidentified user after I push all my files to my github 如何将已建立的本地git存储库链接到新的远程存储库并将所有文件推送到远程? - How do I link an already established local git repository to a new remote repository and push all files to remote? 如何让“git push production”推送存储库中的所有文件? - How can I make "git push production" push all files in repository?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM