1

I have already committed the following files in the local Git repository:

  • dir1/file1
  • dir1/file2
  • dir2/file3
  • dir2/file4

Now I want to push only two files out of four files, i.e., dir1/file1 and dir2/fil4 to GitLab. Is it possible? If yes, what is the appropriate Git command?

1
  • 1
    The simple answer is "no": you don't push files, you push commits. The longer answer is that there are many ways of making a new commit, but they require more details about what you're trying to achieve, and are probably well documented if you read some general git tutorials. Commented Oct 22, 2021 at 20:48

1 Answer 1

2

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.

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>. 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.
  • 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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.