项目错误恢复

  • 方法一:
$ echo >> about.html    # Appends a newline to about.html

 

$ echo > about.html   # overwrite about.html with a newline

 

[website (master)]$ git checkout -f

undo the changes by passing the -f (force) option to checkout, which forces Git to check out HEAD. The state of the repository as of the most recent commit (a state known as HEAD)

 

  • 方法二:

Another source of robustness against error is using branches.

当在一个分支有误时:

$ git branch -D test-branch

当错误涉及bug和缺陷在当前项目, 可以用git log 获取SHAs, check out 对应的版本:

$ git log
commit 8c19674468a67720b9ba61a783e81f97062874bf
Author: Michael Hartl <michael@michaelhartl.com>
Date:   Mon Dec 21 21:27:56 2015 -0800

    Add a README

commit 69b955490caf12552e83d476820d29475fa35010
Author: Michael Hartl <michael@michaelhartl.com>
Date:   Mon Dec 21 21:02:20 2015 -0800

    Add some HTML structure
View Code

 

$ git checkout 03aff34ec4f9690228e057a4252bcca169a868b4

 

在连接不到远程仓库,想获取当前项目的远程仓库url :

git config --get remote.origin.url

 

如果您需要完整的输出,并且您所在的网络可以到达原始服务器所在的远程repo :

git remote show origin

 

与origin master建立连接:

git remote add origin git@github.com:XXXX/nothing2.git

 

 把某个分支上的内容都拉取到本地:

git pull origin dev(远程分支名称)

  git checkout -b P2C3-Solution(本地新建分支) origin/P2C3-Solution(远程分支)

git删除了本地文件,从远程仓库中恢复:

在本地删除了文件,使用git pull,无法从远程项目中拉取下来

查看项目的状态,会显示出你删除的数据

git status 

进入被删除的文件的目录下,假设删除的文件名为 test.txt
然后进行下列操作,可以成功找回:

git reset HEAD test.txt
git checkout test.txt

 

merge冲突,退回到merge前:

git reset --merge

 

查看配置信息 

git config --list

 

把远程分支拉到本地:

git fetch origin dev(dev为远程仓库的分支名)