Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

33.如果一个实习生,他本地git的A分支被误删了, A分支代码没有被push到远程,如何找到之前A的提交记录和代码 #35

Open
airuikun opened this issue Aug 4, 2019 · 4 comments

Comments

@airuikun
Copy link
Owner

airuikun commented Aug 4, 2019

第 3 题:如果一个实习生,他本地git的A分支被误删了, A分支代码没有被push到远程,如何找到之前A的提交记录和代码

@mailylqj
Copy link

mailylqj commented Aug 5, 2019

git reflog 可以查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作)

例如执行 git reset --hard HEAD~1,退回到上一个版本,用git log则是看不出来被删除的commitid,用git reflog则可以看到被删除的commitid,我们就可以买后悔药,恢复到被删除的那个版本。

@wanghaooo
Copy link

  • git log -g 找到最近一次提交的commit记录,并记下commit id
  • git branch newbranch commit_id生成一个newbranch新分支
  • 切到newbranch分支

@JackFrankWen
Copy link

ust two commands save my life

  1. This will list down all previous HEADs

git reflog
2. This will revert the HEAD to commit that you deleted.

git reset --hard
ex. git reset --hard b4b2c02

@johanazhu
Copy link

git reflog:查找所有提交的 commit 历史
git reset --hard 9acd4e9:将git指针回溯到其中的一个版本
commit 记录与 branch 无关

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants