问题
I have changed a single file in a subdirectory of my repository and I want to push just that file to Github.
I've made a small change to one file, and I don't want to re-upload the entire repository.
It seems like all of the instructions that I've seen so far require me to merge locally with the master and then push my local master to the remote origin.
How can I push just that one file?
回答1:
When you do a push, git only takes the changes that you have committed.
Remember when you do a git status
it shows you the files you changed since the last push?
Once you commit those changes and do a push they are the only files that get pushed so you don't have to worry about thinking that the entire master gets pushed because in reality it does not.
How to push a single file:
git commit yourfile.js
git status
git push origin master
回答2:
Very simple. Just follow these procedure:
1. git status
2. git add {File_Name} //the file name you haven been changed
3. git status
4. git commit -m '{your_message}'
5. git push origin master
回答3:
Let me start by saying that the way git works is you are not pushing/fetching files; well, at least not directly.
You are pushing/fetching refs, that point to commits. Then a commit in git is a reference to a tree of objects (where files are represented as objects, among other objects).
So, when you are pushing a commit, what git does it pushes a set of references like in this picture:
If you didn't push your master branch yet, the whole history of the branch will get pushed.
So, in your example, when you commit and push your file, the whole master branch will be pushed, if it was not pushed before.
To do what you asked for, you need to create a clean branch with no history, like in this answer.
回答4:
If you commit one file and push your revision, it will not transfer the whole repository, it will push changes.
回答5:
It will only push the new commits. It won't push the whole "master" branch. That is part of the benefit of working with a Distributed Version Control System. Git figures out what is actually needed and only pushes those pieces. If the branch you are on has been changed and pushed by someone else you'll need to pull first. Then push your commits.
回答6:
Push only single file
git commit -m "Message goes here" filename
Push only two files.
git commit -m "Message goes here" file1 file2
来源:https://stackoverflow.com/questions/13479763/how-to-push-a-single-file-in-a-subdirectory-to-github-not-master