使用Git与GitHub协同开发并搭建私有GitLab代码托管(3)

no changes added to commit (use "git add" and/or "git commit -a")
niko@niko-notebook:~/StydyGit$ git add .  # 跟踪当前状态
niko@niko-notebook:~/StydyGit$ git commit -m "del file2.txt"  # 将代码提交到本地库
[master db6e563] del file2.txt
1 file changed, 1 deletion(-)
delete mode 100644 file2.txt
niko@niko-notebook:~/StydyGit$ git reflog  # 查看形成一个版本信息db6e563
db6e563 (HEAD -> master) HEAD@{0}: commit: del file2.txt
bcf8ce2 HEAD@{1}: commit: first reset
80cbf7f HEAD@{2}: reset: moving to 80cbf7f
b4a5442 HEAD@{3}: commit: modifiy file.txt
17acb24 HEAD@{4}: commit: add file3.txt
80cbf7f HEAD@{5}: commit: add file2.txt
e6442a4 HEAD@{6}: commit: modifiy file.txt
5f9adfe HEAD@{7}: commit (initial): add file.txt
niko@niko-notebook:~/StydyGit$ git reset --hard bcf8ce2  # 回退到上一个版本
HEAD is now at bcf8ce2 first reset
niko@niko-notebook:~/StydyGit$ ls    # file2.txt文件已经存在
file.txt  file2.txt  file3.txt
niko@niko-notebook:~/StydyGit$ git status    # 查看当前跟踪状态
On branch master
nothing to commit, working tree clean
niko@niko-notebook:~/StydyGit$ git reflog  # 生成一个版本信息
bcf8ce2 (HEAD -> master) HEAD@{0}: reset: moving to bcf8ce2
db6e563 HEAD@{1}: commit: del file2.txt
bcf8ce2 (HEAD -> master) HEAD@{2}: commit: first reset
80cbf7f HEAD@{3}: reset: moving to 80cbf7f
b4a5442 HEAD@{4}: commit: modifiy file.txt
17acb24 HEAD@{5}: commit: add file3.txt
80cbf7f HEAD@{6}: commit: add file2.txt
e6442a4 HEAD@{7}: commit: modifiy file.txt
5f9adfe HEAD@{8}: commit (initial): add file.txt

git diff

使用git diff --staged比较工作区与暂存区的不同。

使用git diff --cached比较暂存区与本地库的不同。

分支管理

分支可以并行推进项目的开发,开发的某一个功能如果失败不会影响项目整体。

使用Git与GitHub协同开发并搭建私有GitLab代码托管服务器

查看分支(git branch -v)

niko@niko-notebook:~/StydyGit$ git branch -v * master bcf8ce2 first reset

创建分支(git branch branchName)

niko@niko-notebook:~/StydyGit$ git branch hot_fix

切换分支(git checkout branchName)

niko@niko-notebook:~/StydyGit$ git checkout hot_fix Switched to branch 'hot_fix' niko@niko-notebook:~/StydyGit$ git branch -v # 星号所在分支就是当前分支 * hot_fix bcf8ce2 first reset master bcf8ce2 first reset

合并分支(git merge branchName)

niko@niko-notebook:~/StydyGit$ vim file3.txt  # 修改文件
niko@niko-notebook:~/StydyGit$ git status      # 查看分支状态
On branch hot_fix
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:  file3.txt

no changes added to commit (use "git add" and/or "git commit -a")
niko@niko-notebook:~/StydyGit$ git add .      # 添加到当前分支的跟踪状态
niko@niko-notebook:~/StydyGit$ git commit -m "fix bug by xvge"  # 提交代码
[hot_fix 40376b9] fix bug by xvge
1 file changed, 1 insertion(+)
niko@niko-notebook:~/StydyGit$ git checkout master  # 切换到主分支
Switched to branch 'master'
niko@niko-notebook:~/StydyGit$ git merge hot_fix    # 将hot_fix合并到master
Updating bcf8ce2..40376b9
Fast-forward
file3.txt | 1 +
1 file changed, 1 insertion(+)
niko@niko-notebook:~/StydyGit$ git stataus        # 查看主分支状态
git: 'stataus' is not a git command. See 'git --help'.

The most similar command is
      status
niko@niko-notebook:~/StydyGit$ git status
On branch master
nothing to commit, working tree clean
niko@niko-notebook:~/StydyGit$ git reflog  # 产生几个新版本
40376b9 (HEAD -> master, hot_fix) HEAD@{0}: merge hot_fix: Fast-forward
bcf8ce2 HEAD@{1}: checkout: moving from hot_fix to master
40376b9 (HEAD -> master, hot_fix) HEAD@{2}: commit: fix bug by xvge
bcf8ce2 HEAD@{3}: checkout: moving from master to hot_fix
bcf8ce2 HEAD@{4}: reset: moving to bcf8ce2
db6e563 HEAD@{5}: commit: del file2.txt
bcf8ce2 HEAD@{6}: commit: first reset
80cbf7f HEAD@{7}: reset: moving to 80cbf7f
b4a5442 HEAD@{8}: commit: modifiy file.txt
17acb24 HEAD@{9}: commit: add file3.txt
80cbf7f HEAD@{10}: commit: add file2.txt
e6442a4 HEAD@{11}: commit: modifiy file.txt
5f9adfe HEAD@{12}: commit (initial): add file.txt

合并代码时产生了冲突

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/31b852f376394eb7f474e4381529dd22.html