简体   繁体   English

git push origin new_local_branch推送所有文件

[英]git push origin new_local_branch pushes all files

I cloned a distant git repository on my local machine. 我在本地计算机上克隆了一个远程git存储库。

I created a branch with 我创建了一个分支

git checkout -b new_local_branch

I did some changes. 我做了一些改变。

Now I want to push my local branch to the remote repository with 现在我想使用以下命令将本地分支推送到远程存储库

git push origin new_local_branch

I am quite surprised that git is sending all files to the remote repository (not only the modified one) Is it normal? 我很惊讶git将所有文件发送到远程存储库(不仅是修改过的文件),这正常吗? How can I avoid that? 我该如何避免呢?

Thanks in advance 提前致谢

You must have misunderstood something. 您一定有误解。 Git push sends only the objects that are new. Git push仅发送新的对象。 For example, have a look at this simplistic sequence where I update one file (README.txt) and push that to a new remote branch. 例如,看看这个简单的序列,在该序列中我更新一个文件(README.txt)并将其推送到新的远程分支。

$ git checkout -b new_branch
Branch new_branch set up to track local branch master.
Switched to a new branch 'new_branch'

$ echo "New readme file content" > README.txt 

$ g commit -a -m "Commit only on new branch"
[new_branch 8d8f56d] Commit only on new branch
 1 file changed, 1 insertion(+), 3 deletions(-)

$ git log --oneline --decorate
8d8f56d (HEAD, new_branch) Commit only on new branch
d101a0e (origin/master, master) Small update
2d02c36 Initial commit

$ git push origin new_branch
Counting objects: 3, done.
Writing objects: 100% (3/3), 283 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/myrepo.git/
 * [new branch]      new_branch -> new_branch

Git push sent only 3 objects. Git push仅发送了3个对象。 Those are: 那些是:

  1. The new blob object containing the text: "New readme file content" 包含文本的新Blob对象:“新自述文件内容”
  2. The new tree object representing the repo root directory (which points to the new blob object) 表示存储库根目录的新树对象(指向新的blob对象)
  3. The new commit object 8d8f56d which we could see in the git log output 我们可以在git log输出中看到的新提交对象8d8f56d

Note that the old commit objects 2d02c36, d101a0e and trees/blobs related to those commits were not sent, because the remote repo already had those commits. 请注意,未发送旧的提交对象2d02c36,d101a0e和与那些提交相关的树/ blob,因为远程回购库已经具有那些提交。 Note that if you had a deep directory structure inside your repo, even if you update only one file, you may need to send quite many new tree objects, one for each parent directory of the changed file. 请注意,如果您的存储库中有一个深层目录结构,则即使您仅更新一个文件,也可能需要发送许多新的树对象,每个新的树对象用于已更改文件的每个父目录。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM