Git - 签出分支后恢复提交

时间:2017-08-18 19:43:11

标签: git github

我刚刚开始使用git,我很害怕我可能已经失去了一整天的努力工作。有人可以看看并告诉我是否有办法恢复该提交?

我在一家分公司工作。我添加了文件,提交并执行推送到另一个分支(我混淆了分支名称......)。然后检查出来掌握因为我想合并一切。这就是我认为搞砸了的地方。有没有办法从我的提交中恢复文件?感谢

Yuri:Python yurir.tonin$ git checkout -b branch1_2files
M   .DS_Store
Switched to a new branch 'branch1_2files'
Yuri:Python yurir.tonin$ git status
On branch branch1_2files
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   .DS_Store
    modified:   GUI/dicomROI_more_files.py
    modified:   GUI/dicomROI_single_file.py

no changes added to commit (use "git add" and/or "git commit -a")
Yuri:Python yurir.tonin$ git  add .
Yuri:Python yurir.tonin$ git commit -m "Edited file dicomROI_more_files.py to receive and analyze data from multiple aquisitons, that is, from multiple folders containing DICOM images obtained at different flip angles)"
[branch1_2files 666a146] Edited file dicomROI_more_files.py to receive and analyze data from multiple aquisitons, that is, from multiple folders containing DICOM images obtained at different flip angles)
 3 files changed, 140 insertions(+), 53 deletions(-)
Yuri:Python yurir.tonin$ git push origin GUI_branch
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.10 KiB | 1.10 MiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/yurirt94/TCC.git
 * [new branch]      GUI_branch -> GUI_branch
Yuri:Python yurir.tonin$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
Yuri:Python yurir.tonin$ git merge GUI_branch
warning: Cannot merge binary files: .DS_Store (HEAD vs. GUI_branch)
Auto-merging GUI_old/dicomROI_v3.py
Auto-merging .DS_Store
CONFLICT (add/add): Merge conflict in .DS_Store
Automatic merge failed; fix conflicts and then commit the result.
Yuri:Python yurir.tonin$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

2 个答案:

答案 0 :(得分:1)

提交仍在您的本地branch1_2files分支中。

只需中止合并并返回该分支

git merge --abort
git checkout branch1_2files

现在可能你应该修正错误的推动并再次进行合并

答案 1 :(得分:0)

如果你已经进入了已经检查过的分支,那么你只需要检查那个分支,你就可以通过git log查看你的提交。

>>> git checkout branch1_2files
>>> git log

您应该无法结帐您正在使用的分支机构,并且可以将待处理的更改准备好上传到主人,所以我很确定您没有消除您的工作。