簡體   English   中英

git push origin new_local_branch推送所有文件

[英]git push origin new_local_branch pushes all files

我在本地計算機上克隆了一個遠程git存儲庫。

我創建了一個分支

git checkout -b new_local_branch

我做了一些改變。

現在我想使用以下命令將本地分支推送到遠程存儲庫

git push origin new_local_branch

我很驚訝git將所有文件發送到遠程存儲庫(不僅是修改過的文件),這正常嗎? 我該如何避免呢?

提前致謝

您一定有誤解。 Git push僅發送新的對象。 例如,看看這個簡單的序列,在該序列中我更新一個文件(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僅發送了3個對象。 那些是:

  1. 包含文本的新Blob對象:“新自述文件內容”
  2. 表示存儲庫根目錄的新樹對象(指向新的blob對象)
  3. 我們可以在git log輸出中看到的新提交對象8d8f56d

請注意,未發送舊的提交對象2d02c36,d101a0e和與那些提交相關的樹/ blob,因為遠程回購庫已經具有那些提交。 請注意,如果您的存儲庫中有一個深層目錄結構,則即使您僅更新一個文件,也可能需要發送許多新的樹對象,每個新的樹對象用於已更改文件的每個父目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM