How to push a single file in a subdirectory to Github (not master)

前端 未结 7 1679
傲寒
傲寒 2020-12-23 13:56

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 wa

7条回答
  •  情话喂你
    2020-12-23 14:43

    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:

    git commits

    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.

提交回复
热议问题