我正在使用git中的2个本地分支,让我们称它们为alerts_v2和。我对A进行了一些更改,提交了它们,然后切换到B.我在B中完成了一些工作,现在切换回分支A后,我从远程分支中更改了文件并将其与我的本地更改混合在一起。因此,当我执行git状态时,我会列出一堆文件,但我没有更改。我的目标是让我的分支与远程主服务器匹配,直到我提交更改,然后只有当我执行'git status'时才会显示我的本地更改。
更新: 我已经粘贴了一份reflog。分支alerts_v2对应于上例中的分支A.我实际上在切换回alerts_v2之前使用了几个分支,因此分支B实际上代表了一些分支(但我不认为这是重要的)。
条目23a03b7是我离开alerts_v2的地方,条目f6c143e是我搬回去的地方。
31b259f HEAD@{1}: origin/master: updating HEAD
74aab0b HEAD@{2}: commit: Blap
31b259f HEAD@{3}: origin/master: updating HEAD
f6c143e HEAD@{4}: checkout: moving from version to alerts_v2
31b259f HEAD@{5}: commit: Added version information popup
b2c9ce3 HEAD@{6}: origin/master: updating HEAD
f0c9b0c HEAD@{7}: commit: Blap
b2c9ce3 HEAD@{8}: origin/master: updating HEAD
abba6bc HEAD@{9}: commit: Blap
b2c9ce3 HEAD@{10}: origin/master: updating HEAD
34ecadc HEAD@{11}: commit: Blap
f3cb5f9 HEAD@{12}: commit: Blap
b2c9ce3 HEAD@{13}: origin/master: updating HEAD
3a8c25d HEAD@{14}: commit: Blap
b2c9ce3 HEAD@{15}: origin/master: updating HEAD
6820bd3 HEAD@{16}: pull : Merge made by recursive.
ad215b1 HEAD@{17}: commit: Blap
27bd651 HEAD@{18}: commit: Blap
e74af44 HEAD@{19}: checkout: moving from e74af44ae40484d837e0295c1622731de1dcb84e to version
e74af44 HEAD@{20}: pull : Fast-forward
76bb1fa HEAD@{21}: checkout: moving from ncli to master2
e74af44 HEAD@{22}: commit: Added download NCLI button
ed2d3c4 HEAD@{23}: origin/master: updating HEAD
9ad842a HEAD@{24}: pull : Merge made by recursive.
b99d663 HEAD@{25}: commit: Added download ncli button
e83d923 HEAD@{26}: origin/master: updating HEAD
719791a HEAD@{27}: commit: Added download NCLI button
9e613d1 HEAD@{28}: commit: Added download ncli button
e83d923 HEAD@{29}: origin/master: updating HEAD
a4d6d42 HEAD@{30}: pull : Merge made by recursive.
39f5fed HEAD@{31}: commit: Add NCLI download capability
76bb1fa HEAD@{32}: checkout: moving from 76bb1fa890089ca732322eba7ad9e74486e2bda1 to ncli
76bb1fa HEAD@{33}: checkout: moving from master to master2
9248d50 HEAD@{34}: commit: Blap
76bb1fa HEAD@{35}: origin/master: updating HEAD
23a03b7 HEAD@{36}: checkout: moving from alerts_v2 to master
f6c143e HEAD@{37}: commit: Blap
8a4b166 HEAD@{38}: commit: Blap
76bb1fa HEAD@{39}: pull : Fast-forward
d245574 HEAD@{40}: pull : Fast-forward
c1e5e92 HEAD@{41}: pull : Fast-forward
b8602a5 HEAD@{42}: commit: Changed Alert event handling
db06232 HEAD@{43}: origin/master: updating HEAD
e807ef7 HEAD@{44}: rebase: Commit
db06232 HEAD@{45}: checkout: moving from alerts_v2 to db06232a413d79fd5607c5618dce8a316efbe84
8cc089f HEAD@{46}: pull : Merge made by recursive.
c74acd9 HEAD@{47}: commit: Commit
4a0c135 HEAD@{48}: commit: Changed the name attribute in the AlertModel to map to Alert Type
ed087cd HEAD@{49}: origin/master: updating HEAD
3db4639 HEAD@{50}: commit: Changed the name attribute in the AlertModel to map to Alert Type
ed087cd HEAD@{51}: origin/master: updating HEAD
ecaea02 HEAD@{52}: commit: Changed the name attribute in the AlertModel to map to Alert Type
ed087cd HEAD@{53}: origin/master: updating HEAD
36323fa HEAD@{54}: pull : Merge made by recursive.
18034e5 HEAD@{55}: commit: Changed AlertMode name attribute to map to Alert Type
a46de98 HEAD@{56}: origin/master: updating HEAD
6fae22b HEAD@{57}: checkout: moving from alerts_patch1 to alerts_v2
8efde4b HEAD@{58}: checkout: moving from alerts_v2 to alerts_patch1
6fae22b HEAD@{59}: commit: Made some changes
a46de98 HEAD@{60}: checkout: moving from a46de98c050cfc8b61b5efccb20d0a271b3959d2 to alerts_v
a46de98 HEAD@{61}: checkout: moving from a46de98c050cfc8b61b5efccb20d0a271b3959d2 to events1
a46de98 HEAD@{62}: commit: Initial implementation of Alert Manager, Namespace Manager and Pol
5cfb8a2 HEAD@{63}: origin/master: updating HEAD
f978dae HEAD@{64}: commit: Initial implementation of Alert Manager, Namespace Manager and Pol
5cfb8a2 HEAD@{65}: origin/master: updating HEAD
答案 0 :(得分:0)
只要这些更改不会在新分支上产生冲突,当您进行本地更改时签出(或切换)到其他分支将成功。这些可能是您看到的已更改文件,您在分支B上的待处理工作。
您可以使用硬重置删除对已跟踪文件的所有更改:
git reset --hard HEAD
但是这会删除你的更改,如果你想保存它们,你可以存储它们:
git stash
Stashing将创建您的更改记录,并将所有跟踪的文件还原为HEAD
中的状态。您可以使用git stash list
查看您的藏匿列表。
当您移回正确的分支时,您可以检索保存的存储:
git stash pop