1、git 提交代码错误实例分析
$ git push origin master
To [email protected]:k6.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:k6.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'Note about
fast-forwards' section of 'git push --help' for details.
cbk@YCS:~/work/k6_130708/k6$ git fecth
git: 'fecth' is not a git command. See 'git --help'.
git push 错误,因为没有先pull最新的代码,需要以下操作:
$ git fetch origin
$ git merge origin/master
$ git push origin master
如果安装git后没有设置你的用户名称和e-mail地址,还需要先执行:
$ git config --global user.name "cbk"
$ git config --global user.email [email protected]
这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:
重申一遍,你只需要做一次这个设置。如果你传递了 --global 选项,因为Git将总是会使用该信息来处理你在系统中所做的一切操作。如果你希望在一个特定的项目中使用不同的名称或e-mail地址,你可以在该项目中运行该命令而不要--global选项。
具体到此问题,如果没有设置你的用户名称和e-mail地址,则一直正确无法push代码。
2、Git 跟踪一个文件的提交历史记录
在跟踪Android代码是,有时候发现某个关键文件被改动了,需要跟踪查看对这个关键文件的所有commit的记录,以便理解其中的修改原因和过程:
git log -p “file name”
显示这个文件的每一行的最后提交commit,方便定位commit:
git blame “file name"
git show 75704c8543b033619a80439ddb0fd69cc7cb172c
3、git初始化之git config
git config文件的override顺序是3)>1)>2).
4.版本回退
git reset --hard commit_id
git checkout commit_id
git clean –df commit_id