# Git Stash: ضع التعديلات غير المحفوظة جانبا

Published: 2026-12-03

Rights: original
Source: https://kairospan.com/res/git-stash-full-ar
أوقف العمل مؤقتًا وارجع بشجرة نظيفة: يحفظ `git stash` تعديلات الملفات المتتبَّعة في مكدّس، ويعيد `git stash pop` أحدث إدخال ثم يحذفه من المكدّس.

كل أمر أدناه هو الأمر الذي نُفّذ فعلا، وكل كتلة ناتج منسوخة من السجل المسجَّل. معرّفات الاختبارات وبصمات السجلات وحالات الخروج في جدول الأدلة.

(الاختبار: نُفّذت 6 اختبارات، TE-59-A وTE-59-B وTE-59-C وTE-308-A وTE-308-B وTE-308-C. الخروج غير الصفري المتوقع هو في TE-59-C وTE-308-A (حالة الخروج 1 في كليهما). لكل صف سجل مسجَّل، وحالات الخروج وبصمات السجلات في جدول الأدلة.)

### TE-59-A: يُنظّف stash شجرة العمل المتتبَّعة ويستعيد pop التعديل

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt
```

الأمر:

```bash
git stash >/dev/null; echo clean=$(git status --porcelain | wc -l); echo list_before=$(git stash list | wc -l); git stash pop >/dev/null; echo list_after=$(git stash list | wc -l); echo restored=$(git status --porcelain | wc -l); cat f.txt
```

الناتج المسجَّل:

```
clean=0
list_before=1
list_after=0
restored=1
one
two
```

حالة الخروج: 0. يطابق الناتج النص المتوقع الذي كُتب قبل التشغيل.

### TE-59-B: يحفظ git stash push -m التعديل برسالة يعرضها git stash list

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt
```

الأمر:

```bash
git stash push -q -m wip; git stash list
```

الناتج المسجَّل:

```
stash@{0}: On main: wip
```

حالة الخروج: 0. تطابق هذه الحالة والناتج ما كُتب قبل التشغيل.

### TE-59-C: خروج غير صفري متوقع: ينتهي git stash pop بحالة الخروج 1 عندما تكون قائمة stash فارغة

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
```

الأمر:

```bash
git stash pop
```

الناتج المسجَّل: لا شيء، كان الخرج القياسي فارغا.

الخطأ القياسي من التشغيل نفسه:

```
No stash entries found.
```

حالة الخروج: 1. تطابق هذه الحالة والناتج ما كُتب قبل التشغيل.

TE-59-B: حسب الإعداد، في f.txt تعديل غير مجهَّز للـ commit. حفظه الأمر git stash push -m wip، وعرض git stash list إدخالا واحدا هو stash@{0}: On main: wip. TE-59-C: حسب الإعداد، لم يُحفظ شيء في stash. انتهى git stash pop بحالة الخروج 1 وطبع No stash entries found. إلى الخطأ القياسي.

## git stash pop: التعارضات وإدخال محدد وapply

Q: ماذا يفعل git stash pop عند حدوث تعارض؟
A: يبلّغ عن التعارض وينتهي بحالة الخروج 1 ويُبقي الإدخال في قائمة stash (TE-308-A). وهذا ما يقوله دليل git-stash: إذا فشل تطبيق الحالة بسبب تعارضات فلا يُحذف الإدخال من قائمة stash، وتحل التعارضات يدويا ثم تنفّذ `git stash drop` بنفسك.

Q: كيف أنفّذ pop لإدخال أقدم لا الأحدث؟
A: أعط `git stash pop` اسم الإدخال من `git stash list`، مثل `stash@{1}`. يبقى الإدخال الآخر في القائمة (TE-308-B).

Q: ما الفرق بين pop وapply؟
A: يعيد `git stash apply` التعديلات ويُبقي الإدخال. ويحذفه `git stash drop`. أما `pop` فيفعل الأمرين في خطوة واحدة (TE-308-C، وTE-59-A أعلاه لـ pop وحده).


### TE-308-A: خروج غير صفري متوقع: ينتهي git stash pop مع تعارض بحالة الخروج 1 ويُبقي إدخال stash

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' > f.txt; git stash -q
printf 'three\n' > f.txt; git commit -qam three
```

الأمر:

```bash
git stash pop >../out.txt 2>../err.txt; rc=$?
grep -h -E '^(CONFLICT|The stash entry)' ../out.txt ../err.txt
echo list_after=$(git stash list | wc -l)
git status -s
exit $rc
```

الناتج المسجَّل:

```
CONFLICT (content): Merge conflict in f.txt
The stash entry is kept in case you need it again.
list_after=1
UU f.txt
```

حالة الخروج: 1. هذه هي الحالة المسجَّلة في سجل TE-308-A.

### TE-308-B: يطبّق git stash pop مع اسم stash ذلك الإدخال ويترك الإدخال الآخر في القائمة

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'a\n' > f.txt; git stash push -q -m first
printf 'b\n' > f.txt; git stash push -q -m second
```

الأمر:

```bash
git stash list
git stash pop -q 'stash@{1}'; echo pop_exit=$?
cat f.txt
git stash list
```

الناتج المسجَّل:

```
stash@{0}: On main: second
stash@{1}: On main: first
pop_exit=0
a
stash@{0}: On main: second
```

حالة الخروج: 0. هذه هي الحالة المسجَّلة في سجل TE-308-B.

### TE-308-C: يُبقي git stash apply الإدخال، ويحذفه git stash drop

التحضير لهذا التشغيل، داخل مجلد مؤقت (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt; git stash -q
```

الأمر:

```bash
git stash apply -q; echo list_after_apply=$(git stash list | wc -l) file_lines=$(wc -l < f.txt)
git stash drop -q; echo list_after_drop=$(git stash list | wc -l)
```

الناتج المسجَّل:

```
list_after_apply=1 file_lines=2
list_after_drop=0
```

حالة الخروج: 0. هذه هي الحالة المسجَّلة في سجل TE-308-C.

TE-308-A: حسب الإعداد، حُفظ f.txt في stash بالمحتوى two، ثم غيّر commit جديد الملف نفسه إلى three. طبع git stash pop العبارة CONFLICT (content): Merge conflict in f.txt والعبارة The stash entry is kept in case you need it again. بقي في القائمة إدخال واحد، وأظهر git status -s السطر UU f.txt. TE-308-B: حسب الإعداد، يوجد إدخالان هما first (الأقدم) وsecond (الأحدث). انتهى git stash pop 'stash@{1}' بحالة الخروج 0، وقرأ f.txt القيمة a، ولم يبقَ في القائمة سوى stash@{0}: On main: second. TE-308-C: ترك git stash apply إدخالا واحدا في القائمة وكان في f.txt سطران. ثم ترك git stash drop صفر إدخالات.

## الحدود

يغطي TE-59-A وTE-59-B تعديلا غير مجهَّز على ملف متتبَّع، ويغطي TE-59-C حالة stash فارغ. لم تُختبر الملفات غير المتتبَّعة ولا التعديلات المجهَّزة. يغطي TE-308-A تعارضا عند pop، ويطبّق TE-308-B إدخالا محددا بـ pop، ويشغّل TE-308-C كلا من `apply` و`drop` مرة واحدة. غير مختبر في هذه الصفحة: الأوامر الفرعية `show` و`branch` و`clear`، والخيار `--index` مع `pop`، وخيارات `push`: `-p` أو `--patch`، و`-k` أو `--keep-index`، و`-u` أو `--include-untracked`، و`-a` أو `--all`، و`--pathspec-from-file` مع `--pathspec-file-nul`. يعرضها نص الاستخدام الذي يطبعه `git stash -h` في git 2.34.1. لم يستخدمها أي أمر `git stash` هنا.

## Source

- https://git-scm.com/docs/git-stash

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-59-A` | يُنظّف stash شجرة العمل المتتبَّعة ويستعيد pop التعديل | 0 | PASS | `77a379f0397b` |
| `TE-59-B` | يحفظ git stash push -m التعديل برسالة يعرضها git stash list | 0 | PASS | `6cf540b5aec0` |
| `TE-59-C` | خروج غير صفري متوقع: ينتهي git stash pop بحالة الخروج 1 عندما تكون قائمة stash فارغة | 1 | PASS | `b014757852b8` |
| `TE-308-A` | خروج غير صفري متوقع: ينتهي git stash pop مع تعارض بحالة الخروج 1 ويُبقي إدخال stash | 1 | PASS | `ba6d136d12fe` |
| `TE-308-B` | يطبّق git stash pop مع اسم stash ذلك الإدخال ويترك الإدخال الآخر في القائمة | 0 | PASS | `cb5d80e63cfd` |
| `TE-308-C` | يُبقي git stash apply الإدخال، ويحذفه git stash drop | 0 | PASS | `7697a6182f87` |

سُجّل على: bash 5.1.16(1)-release؛ git version 2.34.1؛ Python 3.10.12. اللغة C.UTF-8، المنطقة الزمنية UTC.
السجلات والبصمات هي نفسها سجلات الصفحة الإنجليزية git-stash-full-en، فهذه الصفحة ترجمة نثر فقط ولم يُجرَ لها تشغيل منفصل. لكل صف سجل مسجَّل فيه أوامر الإعداد والأمر والخرج القياسي والخطأ القياسي وحالة الخروج. أول 12 حرفا من sha256 للسجل في الجدول.

## Related guides
- [git reset: أوضاع soft وmixed وhard على المستودع نفسه](https://kairospan.com/res/git-reset-modes-full-ar)
- [مهام Git اليومية: الفروع وstash والتراجع وحل التعارضات](https://kairospan.com/res/git-workflows-hub-ar)
- [Git يتتبع .env رغم إضافته إلى .gitignore](https://kairospan.com/res/gitignore-env-not-ignored-ar)
