Git学习

git是用于版本控制的。当有一个文档需要进行迭代的更新修改的时候,可能更新到第五个版本的时候,突然想起来第三个版本的有些东西可能需要的,所以想回去查看第三个版本的东西,所以这时候就得在每个版本修改前先做一下备份,以便进行版本控制。Version Control,Git就是做这个事情。

git的大概思想是有一个工作区,一个暂存区,一个仓库,需要被进行版本控制的文件放到工作区然后add到暂存区,从暂存区commit到仓库。

有一个集中的服务器用来作为远程仓库,这个远程仓库可以clone到本地作为一个本地仓库,在这个clone下来的本地仓库中做以上的步骤后再进行push操作即可更新到远程仓库中便于多人协作。

1.每台机器都要先装git客户端

mac默认自带git,windows要去下载git下来。

2.add

例如有一个文件pom.xml要放到仓库中去
首先他要在工作区中,假设在/e/IdeaProjects/train_group1。这是一个工作区,pom.xml在这里面。

git add pom.xml

用git status查看工作区暂存区状态:

$ git status
On branch train_group1_branch_week1
Your branch is up to date with 'origin/train_group1_branch_week1'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   pom.xml

显示有一个新文件pom.xml

3.commit

$ git commit -m "pom.xml"
[train_group1_branch_week1 2768bc4] pom.xml
 1 file changed, 159 insertions(+)
 create mode 100644 C_caifangren/pom.xml

再次用git status查看

$ git status
On branch train_group1_branch_week1
Your branch is up to date with 'origin/train_group1_branch_week1'.

nothing to commit, working tree clean

工作区是clean说明已经提交走了。

4.分支问题

有多个分支,要跳转到某一个分支
先用git branch -a查看

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/train_group1_branch_week1

切换到某一个分支

$ git checkout train_group1_branch_week1
Switched to a new branch 'train_group1_branch_week1'
Branch 'train_group1_branch_week1' set up to track remote branch 'train_group1_branch_week1' from 'origin'.

可以选择需要的分支进行提交

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值