git(三)项目更新

1、当项目没有被修改

git status

结果为

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

2、当项目中修改内容,比如文件内容、文件的增删

#1.README.md更新,但没有进入暂存区
Changes not staged for commit: 
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

------------------------------------------------------------------------
#2.新建了test.py文件,新文件存在于工作目录中,但Git尚未开始跟踪它们
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.py

nothing added to commit but untracked files present (use "git add" to track)

3、这时可以选择推进暂存区,也可以回溯(撤销更新)

#git add 更新的文件
git add README.md

#撤销暂存前的更改 git restore 文件名
git restore test.py

#撤销暂存后的更改 git restore --staged 文件名
git restore --staged test.py

4、将暂存区的内容,提交到本地仓库

# -m (--message),提交信息对更新的描述
git commit -m "添加了test.py测试代码"

5、本地推送至远程仓库(即更新github仓库的项目)

#先查看当前分支
git branch #main

#git push remote_name远程仓库名 local_branch本地分支:remote_branch远程分支
git push origin main #由于local_branch和remote_branch相等,因此可以省略

6、重新拉取更新后的项目,并且合并到本地项目

git fetch: 从远程仓库获取所有分支的更新,但不会自动合并到当前分支。
git merge: 将远程分支的更改合并到当前本地分支。

git pull是fetch和merge的组合:
    git pull [options] [repository] [refspec]
        [options]: 可以是一些选项,比如 --tags 来同步标签。
        [repository]: 通常指远程仓库的名称,默认是 origin。
        [refspec]: 指定要拉取的分支,比如 master 或 main。

 使用如下:

#git pull origin远程仓库名 remote-branch远程分支:local-branch本地分支
git pull #其他默认即可

完成之后,在vscode中会有新的git提醒,那些代码在该文件上发生了变化(当然前提是正在编辑的状态)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值