[github]——Remember a successful HEAD rollback & git push

Preface

There are currently two problems:

  1. Originally I wanted to use "git reset git reset --hard HEAD~1" to cancel the current commit (because the commit is over, I can't push it up... I just canceled it first thinking about it). The result... I pressed my hand twice, so I canceled the current commit and took a step back. I think: go back to the original version.
  2. Then there is git add->git commit->git push origin master, and then an error is reported: "fatal:unable to access …:Could not resolve host:github.com"

Solve the problem one: HEAD fallback

git log --pretty=oneline # 查看当前HEAD之前所有的版本(按q退出)

Insert picture description here

But it didn't work for me, what I want to go back to is: the version above HEAD.

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

Insert picture description here
found it! You can see: HEAD@{3} is the version I just cloned, HEAD@{2} is the version after I committed some modifications, HEAD@{1} is the version I withdrew using "git reset --hard HEAD~1" The commit version, HEAD@{1} is the current version after I reset it again. I want to go back to HEAD@{1} (I found out later that it was not)

git reset --hard HEAD@{
    
    2} # 这是我需要回去的版本,因为:HEAD@{1}时,我的commit被取消了

The problem seems to be solved. Now I need to push the commit to my repository.

Solve problem two: git push origin master

Before discussing with the senior, it may be the problem of network agent:

git config --global -l # 查看网络代理,发现啥也没有

So try to set up proxy

git config --local http.proxy 192.168.4.12:8080

But the comment area said: The port number 8080 is not applicable. I tried to change it to the port number of my server, but it didn't work. The following error was reported:
Connection timed out

Later, I saw the first answer in [4]...Cancel the proxy setting:

git config --global --unset http.proxy

Then, it succeeded:
Insert picture description here

reference:

[1] Three modes of Git Reset
[2] Comparison of git command log and reflog
[3] Git setting network proxy
[4] Some problems with using github? fatal: unable to access;Failed connect to github.com:8087; No error

Guess you like

Origin blog.csdn.net/jokerxsy/article/details/115003443