1.如何创建分支?
使用命令:
git checkout -b master-test1

2.如何将开发好的分支代码合并到 master 主分支上去?
需要执行四步命令:
命令1: git add .
命令2: git commit -m '提交的文字描述'
命令3: git pull origin master
命令4: git push -u origin master-test1

此时我们需要将分支切换到master分支上去:
命令:
git checkout master

在合并代码之前需要先拉取一下:
命令:
git pull

拉取完成之后,就可以进行代码合并了:
命令:
git merge master-test1
将master-test1分支合并到master完成后,再讲master推送到远程分支上:
命令:
git push -u origin master

以上操作就已经完成了代码的合并
3.如何进行代码回滚?
首先通过命令:
git log
查看所有的提交记录

找到想要回滚的版本号进行回滚即可:
命令:
git reset --hard aaadc2232480a3b8105de70e8ce23acf45fa0dc1

4.如何进行 贮藏 / 使用 / 删除贮藏?
贮藏命令:
git stash 或者 git stash save "写一写备注" (推荐)

使用之前通过:
git stash list 查看贮藏的信息
使用贮藏命令:
git stash apply stash@{0} (指定储藏的应用)git stash pop (指定的是最近的储藏)

删除贮藏的信息命令:
git stash drop 储藏的名称

5.git 删除/恢复 本地分支 和 删除/恢复 远程分支?
首先先切到master分支通过命令:
git branch -a (查看已有的本地及远程分支)

删除本地分支:git branch -D 本地分支名称
恢复本地分支:git checkout -b 恢复的分支名称
删除远程分支:git push origin --delete 远程分支名称
恢复远程分支:直接在恢复的分支上面push到远程即可

6.如何解决冲突?
例如当我们修改master-test1中的内容时,不小心修改了master中原有的代码在pull的时候就可能会出现令想不到的冲突,导致代码提交不上:

我们可以根据merge文件名提示:
通过 vim 李凤/index.html 查看到当前的冲突位置

手动解决完冲突之后,就可以继续执行代码合并4步操作了。
7.git如何放弃本地文件修改?
1.未使用git add 缓存代码
1) 放弃某一个本地文件命令: git checkout -- filename
2) 放弃所有文件修改命令: git checkout .
2. 已使用git add 缓存代码,未使用git commit
1)放弃某一个本地文件命令回到git add .之前 : git reset HEAD filename
2)放弃所有文件修改命令回到git add .之前: git reset HEAD
3. 已经用 git commit 提交了代码
1)回退到上一次commit的状态: git reset --hard HEAD^
2)或者回退到任意版本git reset --hard commit id ,使用git log命令查看git提交历史和commit id : git reset --hard commit id
网友评论