初始化git:
git命令
git全局化配置
git config –global core.autocrlf false //禁用自动转换
克隆仓库的命令格式是 git clone [url]
$ git clone https://github.com/libgit2/libgit2
要检查已有的配置信息: git config --list
#克隆git到某个文件夹 (并创建文件夹)
$ git clone https://gitee.com/qingfengxulaihuazishengkai/NewNetworkAdmin.git mylibgit
#初始化目录
$git init
#添加到暂存区
$git add .
详解:git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件。
注意 -A 选项后面还有一个句点。 git add -A . 表示添加所有内容, git add . 表示添加新文件和编辑过的文件不包括删除的文件; git add -u 表示添加编辑或者删除的文件,不包括新添加的文件。
git add –all //提交所有修改到暂存区
#本地仓库
$git commit -m .
Git 每次提交代码, 都要写 Commit message (提交说明), 否则就不允许提交
$ git commit -m "hello world"
#查看状态
$git status
#添加远程仓库
$git remote add pb https://gitee.com/qingfengxulaihuazishengkai/lianshou.git
#查看远程仓库
$git remote -v
#第一次提交用这个
$ git push -u mini master
#将本地的项目更新情况推送到远程仓库
$ git push --set-upstream https://gitee.com/qingfengxulaihuazishengkai/small_program_backstage.git master
#如何将远程仓库里的文件更新到本地?
//方法一
$ git fetch origin master //从远程的origin仓库的master分支下载代码到本地的origin master
$ git log -p master.. origin/master//比较本地的仓库和远程参考的区别
$ git merge origin/master//把远程下载下来的代码合并到本地仓库,远程的和本地的合并
//方法二
$ git fetch origin master:temp //从远程的origin仓库的master分支下载到本地并新建一个分支temp
$ git diff temp//比较master分支和temp分支的不同
$ git merge temp//合并temp分支到master分支
$ git branch -d temp//删除temp
git提交到远程藏库冲突解决
2016年11月07日 20:25:40
阅读数:436
问题
在修改好文件,然后用命令$ git push 向github上的远程仓库推送时,出现下列错误:
error: failed to push some refs to 'https://github.com/GDDXZ/RobotDenso.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因
两人同时fetch了一个分支。 第一个人修改后提交,第二个人提交就失败。
解决方法
1.强制推送
$ git push -f
可以提交,会将remote上第一个人的改动冲掉,比较暴力,不太好。
2.正常解决
先 git fetch origin 然后git merge origin/master, 和本地分支合并, 之后再push。
git 的 一些挽回操作:
1, 如何修改错误的提交信息
如果仅仅推送到暂存区,可使用以下命令
$ git commit --amend -m ”YOUR-NEW-COMMIT-MESSAGE”
注意:已经推送到 remote 仓库 的提交信息,很难撤销。
2 ,提交之前撤销
如果你往暂存区中加入了一些错误的文件,但是还没有提交代码。你可以使用一条简单的命令就可以撤销。如果只需要移除一个文件,那么请输入:
$ git reset <文件名>
或者如果你想从暂存区移除所有没有提交的修改:
$ git reset
//删除文件夹下的所有 .svn 文件
find . -name ".svn"| xargs rm -Rf
//删除文件夹下的所有 .git 文件
find . -name ".git"| xargs rm -Rf