היום למדתי: git intent to add

30/10/2026

בואו נשחק עם גיט. יש לי ריפו ויצרתי בו קובץ חדש בשם demo.py. רואים את זה:

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main?) $ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        demo.py

nothing added to commit but untracked files present (use "git add" to track)
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main?) $

עכשיו אני רוצה לראות מה יש בקובץ. קודם כל אני מנסה git diff - אבל הוא לא מדפיס כלום כי אין שינויים בקבצים של הפרויקט (הקובץ demo.py הוא חדש ומבחינת גיט לא חלק מהפרויקט עדיין).

אז אני מנסה להוסיף אותו עם git add . ועכשיו הוא חלק מהפרויקט:

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main?) $ git add .
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   demo.py

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $ git diff
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $

אבל עדיין git diff לא מדפיס כלום כי אין הבדל בין תוכן הקובץ לתוכן הקובץ ב Staging Area. שוב ברור, git add הוסיף את הקובץ ל staging area.

עד היום השתמשתי ב git diff HEAD או git diff --cached כדי לראות את השינויים אחרי add לדוגמה:

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   demo.py

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $ git diff
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+) $ git diff HEAD
diff --git a/demo.py b/demo.py
new file mode 100644
index 0000000..d77c663
--- /dev/null
+++ b/demo.py
@@ -0,0 +1 @@
+print("hello world from python")

מסתבר ש git add מגיע עם מתג מיוחד בדיוק למקרים האלה, המתג -N או --intent-to-add. מתג זה מסמן לגיט שאנחנו מתכוונים להוסיף את הקובץ הזה לפרויקט בלי להוסיף את התוכן שלו ל Staging בדיוק בשביל שנוכל לראות את ה diff. ככה זה נראה:

ynonp@ynons-MacBook-Air ~/tmp/blog/git (main?) $ git add -N demo.py
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+*) $ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        new file:   demo.py

no changes added to commit (use "git add" and/or "git commit -a")
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+*) $ git diff
diff --git a/demo.py b/demo.py
new file mode 100644
index 0000000..d77c663
--- /dev/null
+++ b/demo.py
@@ -0,0 +1 @@
+print("hello world from python")
ynonp@ynons-MacBook-Air ~/tmp/blog/git (main+*) $

הקובץ מסומן בתור new file אבל התוכן שלו עדיין לא נשמר וכך אנו רואים אותו ב git diff רגיל.