GIT: لا يمكن التراجع عن التغييرات المحلية (خطأ: المسار ... غير مرغوب فيه)
-
26-09-2019 - |
سؤال
لدي حالة شجرة العمل
$ git status foo/bar.txt
# On branch master
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# deleted by us: foo/bar.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
ملف foo/bar.txt
هل هناك وأريد أن أحصل عليه إلى "الحالة غير المتغيرة" مرة أخرى (على غرار "SVN Revert"):
$ git checkout HEAD foo/bar.txt
error: path 'foo/bar.txt' is unmerged
$ git reset HEAD foo/bar.txt
Unstaged changes after reset:
M foo/bar.txt
الآن أصبح الأمر مربكًا:
$ git status foo/bar.txt
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: foo/bar.txt
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo/bar.txt
#
نفس الملف في كلا القسمين ، جديد و تم التعديل؟ ماذا علي أن أفعل؟
المحلول
لقد فعلت ذلك بطريقة خاطئة. من المفترض أن تعيد التعيين أولاً ، لإلغاء مراحل الملف ، ثم الخروج ، لإعادة التغييرات المحلية.
جرب هذا:
$ git reset foo/bar.txt
$ git checkout foo/bar.txt
نصائح أخرى
عملت هذه تماما بالنسبة لي:
$ git reset -- foo/bar.txt
$ git checkout foo/bar.txt
git checkout origin/[branch] .
git status
// لاحظ نقطة (.) في النهاية. وسيكون كل شيء على ما يرام
git checkout foo/bar.txt
هل جربت ذلك؟ (بدون كلمة رئيسية)
عادة ما أعود إلى تغييراتي بهذه الطريقة.
وجدت غيت خبأ مفيد جدا للتعامل الزمني لجميع الحالات "القذرة".
لا تنتمي إلى StackOverflow