[英]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 存储库中提交了以下文件:
Now I want to push only two files out of four files, ie, dir1/file1 and dir2/fil4 to GitLab.现在我只想将四个文件中的两个文件,即dir1/file1和dir2/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:取决于您不想推送所有文件的原因:
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
推送,您可能没有权限这样做。.gitignore
so they don't come up again.如果您根本不想提交这些文件,则应该将它们添加到.gitignore
以免它们再次出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.