廖雪峰官网的git简易教程
在本地安装git,安装方法参考以上教程
git init
-- 把当前目录变成Git可以管理的仓库git remote add origin(远程仓库分支) 远程仓库地址
-- 与远程仓库指定分支建立连接git pull origin(远程仓库分支,origin为默认分支) master(本地仓库主分支)
-- 将远程仓库项目中的内容都拉到本地仓库中git clone 远程仓库地址
-- 会将整个项目包括项目名都克隆到本地仓库git add 新增文件名
-- 告诉Git,把文件添加到提交仓库/暂存区git commit -m “本次提交说明”
-- 告诉Git,把暂存区中的所有文件提交到仓库输入命令 git push origin master
-- 将本地仓库中修改的项目提交到远程仓库中去
当多人同时操作修改同一文件时,push项目时会产生冲突,这时需要查看冲突的地方,必须手动解决冲突后再提交
git status
-- 查看仓库的文件的状态git log
-- 查看文件更新日志git diff
-- 查看仓库文件的不同git rm
与 git rm --cached
-- 删除文件,删除目录时在 file_path 后加 -r
,使用 --cached
保留本地文件,或用 -f
强制删除
- 当我们需要删除暂存区或分支上的文件,同时工作区也不需要这个文件了,可以使用以下命令:
git rm file_path
git commit -m ‘the name of file to be deleted‘
git push- 当我们需要删除暂存区或分支上的文件, 只是不希望这个文件被版本控制, 但本地又需要继续使用, 可以使用以下命令:
git rm --cached file_path
git commit -m ‘the name of file which in remote to be deleted‘
git push
git checkout --file_path
-- 把文件在工作区的修改全部撤销
! [rejected] master -> master (fetch first)
error: 推送一些引用到 'http://116.6.230.45:12304/web/test.git' 失败
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外...
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更...
提示:(如 'git pull ...')。
提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
解决方案:?
因为当前分支的最新提交落后于其对应的远程分支,所以我们先从远程库fetch到更新再和本地库合并,之后就可以git push操作了。
git fetch origin
git merge origin/master
解决方案:
首先将远程仓库和本地仓库关联起来:
git branch --set-upstream-to=origin/master master
然后使用git pull整合远程仓库和本地仓库
git pull --allow-unrelated-histories??? (忽略版本不同造成的影响)
问题解决
原文:https://www.cnblogs.com/vikeykuo/p/11316719.html