湛江做网站软件,代理在线,wordpress添加下载链接,芜湖建设网站本人比较懒#xff0c;不是很爱学习新东西#xff0c;之前用Git一直在用GUI SourceTree#xff0c;今天因为用到Cloud IDEGitHub才迫不得已用一下Git的命令行#xff0c;如果你是Git的新手#xff0c;也分享给你最基本的命令。新建一个Git版本库把一个本地文件夹变成一个G…本人比较懒不是很爱学习新东西之前用Git一直在用GUI SourceTree今天因为用到Cloud IDEGitHub才迫不得已用一下Git的命令行如果你是Git的新手也分享给你最基本的命令。新建一个Git版本库把一个本地文件夹变成一个Git版本库$ git init更新远端最新文件在提交修改之前应先检查是否远端有更新先要应用更新然后再执行本地修改避免文件合并等复杂操作。$ git push origin master查看变更查看从上一次变更提交后都有哪些文件改动使用以下命令$ git status确认变更简单来说就是在提交一次变更之前需要确认哪些文件需要提交进去一般来说我们都是提交所有修改了的文件到这次变更那么就用以下命令$ git add .如果你想取消确认某个文件可以用以下命令$ git reset HEAD 你的文件提交变更提交上一个步骤已经确认过的文件-m后面填上本次变更的备注$ git commit -m 本地变更的备注内容也可以把add放到commit里面一起操作如下$ git commit -a -m 本地变更的备注内容设置远端库本地提交完成后还需要推送到远端第一次提交到远端时需要设置远端库的路径使用以下命令$ git remote add origin 你的远端库URL $ git remote -v如果是GitHub的话可以从GitHub的Quick Setup页面找到URL。设置远端的这个步骤只需要执行一次设置成功后你的远端代号就叫origin。推送到远端本地提交完成后用此命令推送到远端$ git push origin mastermaster是你要推送的分支。你可以用下面的命令让git记住你的用户名密码信息$ git config credential.helper store还可以设置缓存时间记住多久单位秒默认值900$ git config credential.helper cache 缓存时间推送到我的私有Git远端时我遇到报错error: refusing to update checked out branch: refs/heads/mastererror: By default, updating the current branch in a non-bare repositoryerror: is denied, because it will make the index and work tree inconsistenterror: with what you pushed, and will require git reset --hard to matcherror: the work tree to HEAD. error: error: You can set receive.denyCurrentBranch configuration variable to error: ignore or warn in the remote repository to allow pushing into error: its current branch; however, this is not recommended unless you error: arranged to update its work tree to match what you pushed in some error: other way. error: error: To squelch this message and still keep the default behaviour, set error: receive.denyCurrentBranch configuration variable to refuse.原因是因为远端库不是裸库用下面的方法把已有的git库转换成裸库。我之前远端用的是git init并非创建的裸库$ git config --bool core.bare true分支的操作要在当前分支的基础上新建一个分支branch1并切换到该分支可以使用以下命令$ git checkout -b branch1单独切换分支则不加-b参数例如要切换回master分支则$ git checkout master若要将分支master合并到branch1也就是说合并后master和branch1是一样的则用以下命令$ git checkout master $ git merge branch1如果合并遇到冲突则可以通过git status来检查冲突点。要删除分支branch1则用以下命令$ git branch -d branch1