Git Core Lecture

news2024/10/5 2:33:56

1、Git 简介

官方介绍:Git is a fast distributed revision control system (Git 是一个快速的分布式版本控制系统)

2、Git Core Command

2.1 git init

git 工程初始化,会在工作区 (working directory) 根目录中创建.git 目录

# 创建目录
$ mkdir git-init
$ cd git-init

# git 目录初始化
$ git init

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /core-command/git-init/.git/

说明:

  • git init 初始化的集成分支名为:master,可以通过如下命令修改
# 修改默认分支名
$ git config --global init.defaultBranch main

# 再执行初始化时,不再有如上提示
$ git init
Initialized empty Git repository in /temp/.git/
  • 命令行直接修改分支名称,(master -> main)
$ git branch -m main
  • 查看配置修改结果,通过 git config -l 命令
$ git config -l

------
init.defaultbranch=main
------

2.2 git status

显示工作区的状态,可多次使用

刚初始化的工作区是没有可提交的内容

$ git status

No commits yet

nothing to commit (create/copy files and use "git add" to track)

2.3 git add

将文件内容添加到索引中(暂存区)

该命令是在工作区中找到的当前内容更新到索引(暂存区),为下一次提交准备内容。
示例:

# 创建一个文件
$ echo '# Hello Git' > hello-git.md

# 查看工作区状态
$ git status
On branch main

No commits yet

# 未追踪的文件
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	hello-git.md

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

# 将hello-git.md文件添加到索引(暂存区)
$ git add hello-git.md

# 查看工作区状态
$ git status
On branch main

No commits yet
# 将去提交的修改
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   hello-git.md

2.4 git commit

记录仓库的修改,即将索引(暂存区)的内容提交到对象仓库

提交信息包含索引当前的内容和描述变化的给定日志信息。
示例:

# 修改内容提交到对象库
$ git commit -m 'add hello-git.md file'
[main (root-commit) f3de15d] add hello-git.md file
 1 file changed, 1 insertion(+)
 create mode 100644 hello-git.md

$ git status
On branch main
nothing to commit, working tree clean

2.5 git diff

用于对比内容差异,包括工作区和索引,索引和对象库,以及分支之间等其他可对比的内容

示例:

# 修改 hello-git.md 文件
$ cat >> hello-git.md
## Git Core Command
### git init

$ git status
On branch main
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:   hello-git.md

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

$ git diff
# 比较文件,a 是比较源文件,b 是比较目标文件
diff --git a/hello-git.md b/hello-git.md
index ab690e8..db1f38b 100644
--- a/hello-git.md
+++ b/hello-git.md
@@ -1 +1,3 @@
 # Hello Git
+## Git Core Command
+### git init

# 再次提交
# 将 git add 和 git commit 命令合并使用
$ git commit -a -m 'modify hello-git.md file'

说明

  • git 的工作空间分为三种,工作区(工作目录)、索引(暂存区)、对象库
  • git 的工作流:工作区修改的有效内容 添加到 索引 提交 到对象库

2.6 git restore

恢复工作区、索引中已修改的文件,默认恢复工作区

示例:

  • 恢复工作区
# 修改hello-git.md 文件
$ cat >> hello-git.md
git init is used to initial git working tree(directory).

$ git status
On branch main
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:   hello-git.md

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

# 撤回修改(方式一): 将修改的内容手动撤回,如果改动太多,手动改成本太高,非常不推荐
$ vim hello-git.md
......

# 撤回修改(方式二): 使用 git restore 命令恢复修改的内容
$ git restore hello-git.md
# 查看 hello-git.md 内容
$ cat hello-git.md
# Hello Git
## Git Core Command
### git init
  • 恢复索引
# 修改 hello-git.md 文件
$ cat >> hello-git.md
git init is used to initial git working tree(directory).

# 添加到索引
$ git add hello-git.md

# 查看状态
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   hello-git.md

# 从索引中恢复文件(将内容恢复到未追踪状态)
$ git restore --staged hello-git.md

$ git status
On branch main
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:   hello-git.md

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

# 恢复文件
$ git restore hello-git.md

$ git status
On branch main
nothing to commit, working tree clean

# 查看 hello-git.md 内容
$ cat hello-git.md
# Hello Git
## Git Core Command
### git init

2.7 git rm

从工作区和索引中删除文件

示例:

# 1️⃣ 新增文件 git-rm.md
$ echo '# git rm' > git-rm.md
# 第1次删除 git-rm.md 
$ git rm git-rm.md
fatal: pathspec 'git-rm.md' did not match any files (执行报错,git rm 不能删除工作区中未追踪的文件)

# 2️⃣ 添加到索引
$ git add git-rm.md
# 第2次删除 git-rm.md 
$ git rm git-rm.md
error: the following file has changes staged in the index:
    git-rm.md
(use --cached to keep the file, or -f to force removal)

# 3️⃣ 提交到对象库
$ git commit -m 'add git-rm.md file'
# 第3次删除 git-rm.md 
$ git rm git-rm.md
rm 'git-rm.md'
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	deleted:    git-rm.md

# 4️⃣ 提交到对象库
$ git commit -m 'rm git-rm.md file'

2.8 git mv

移动或重命名一个文件,目录或符号链接

示例:

# 1️⃣ 新增文件 git-mv.md
$ echo '# git mv' > git-mv.md
# 第一次 mv
$ git mv git-mv.md git-mv-target.md
fatal: not under version control, source=git-mv.md, destination=git-mv-target.md

# 2️⃣ 添加到索引
$ git add git-mv.md
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-mv.md
# 第二次 mv
$ git mv git-mv.md git-mv-target.md
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-mv-target.md

# 3️⃣ 提交到对象库
$ git commit -m 'add git-mv.md file'
# 第三次 mv
$ git mv git-mv-target.md git-mv-new.md
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	renamed:    git-mv-target.md -> git-mv-new.md
# 4️⃣ 再次提交
$ git commit -m 'mv git-mv-target.md to git-mv-new.md file'

2.9 git reset

重置当前 HEAD 到指定的状态

语法

git reset [<mode>] [<commit>]

mode 模式包含如下几种

  • –mixed(默认值):移动 HEAD 指针并重置索引,不会修改工作区,撤销了提交和暂存的更改,但保留了工作区的修改
  • –soft:只移动 HEAD 指针,暂存区和工作区中的更改都会保留在工作区中,以便再次提交
  • –hard:移动 HEAD 指针并重置索引和工作区,彻底删除了提交以及暂存区和工作区的修改,慎用,因为会导致工作区的内容丢失
  • –merge 和 --keep:较少使用,适用于特殊场景。前者尝试将 HEAD 指向的提交和指定提交之间的差异应用到当前工作区,后者类似 mixed,但保留未修改的文件。

示例:

2.9.1 mode参数
–mixed (默认值)
  • 新增文件的状态流转
# 1️⃣ 新增文件 git-reset.md
$ echo '# git reset' > git-reset.md
# 第1次 git reset
$ git reset
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	git-reset.md

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

# 2️⃣ 添加到索引
$ git add git-reset.md
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-reset.md
# 第2次 git reset (将文件从索引退回到未追踪状态)
$ git reset
$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	git-reset.md

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

# 3️⃣ 提交到对象库
$ git commit -m 'add git-reset.md file'
# 第3次 git reset
$ git reset
On branch main
nothing to commit, working tree clean
  • 修改文件的状态流转
# 1️⃣ 修改文件
$ cat >> git-reset.md
## git reset <mode> <commit>
mode : --soft, --mixed, --hard, --keep etc.
# 第1次 git reset
$ git reset
On branch main
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:   git-reset.md

# 2️⃣ 添加到索引
$ git add git-reset.md
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   git-reset.md
# 第2次 git reset(回退到未追踪状态)
$ git reset
$ git status
On branch main
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:   git-reset.md

# 3️⃣ 提交到对象库
$ git commit -a -m 'modify git-reset.md file'
# 第3次 git reset
$ git reset
On branch main
nothing to commit, working tree clean
–soft
  • 新增文件状态流转
# 1️⃣ 新增文件 git-reset-soft.md
$ echo '# git reset --soft' > git-reset-soft.md
# 第1次 git reset --soft
$ git reset --soft
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	git-reset-soft.md

# 2️⃣ 添加到索引
$ git add git-reset-soft.md
# 第2次 git reset --soft
$ git reset --soft
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-reset-soft.md

# 3️⃣ 提交到对象库
$ git commit -m 'add git-reset-soft.md file'
# 第3次 git reset --soft
$ git reset --soft
$ git status
On branch main
nothing to commit, working tree clean
  • 修改文件状态流转
# 1️⃣ 修改文件 git-reset-soft.md
$ cat >> git-reset-soft.md
# git reset --soft mode is in active.
# 第1次 git reset --soft
$ git reset --soft
On branch main
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:   git-reset-soft.md

# 2️⃣ 添加到索引
$ git add git-reset-soft.md
# 第2次 git reset --soft
$ git reset --soft
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   git-reset-soft.md

# 3️⃣ 提交到对象库
$ git commit -m 'modify git-reset-soft.md file'
# 第3次 git reset --soft
$ git reset --soft
$ git status
On branch main
nothing to commit, working tree clean
–hard
  • 新增文件状态流转
# 1️⃣ 新增文件 git-reset-hard.md
$ echo '# git reset --hard' > git-reset-hard.md
# 第1次 git reset --hard
$ git reset --hard
HEAD is now at 64c3235 modify git-reset-soft.md file

# 2️⃣ 添加到索引
$ git add git-reset-hard.md
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-reset-hard.md
# 第2次 git reset --hard
$ git reset --hard
HEAD is now at 64c3235 modify git-reset-soft.md file (add 到索引的文件被删除了)
$ git status
On branch main
nothing to commit, working tree clean

# 3️⃣ 提交到对象库
$ echo '# git reset --hard' > git-reset-hard.md
$ git add git-reset-hard.md
$ git commit -a -m 'add git-reset-hard.md file'
# 第3次 git reset --hard
$ git reset --hard
$ git status
On branch main
nothing to commit, working tree clean
  • 修改文件状态流转
# 1️⃣ 修改文件 git-reset-hard.md (工作区修改的内容被撤销)
$ cat >> git-reset-hard.md
## git reset --hard
the mode of hard will remove working tree and index.
$ git status
On branch main
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:   git-reset-hard.md
# 第1次 git reset --hard
$ git reset --hard
HEAD is now at 2f1ffeb add git-reset-hard.md file(工作区中修改的内容被删除了)
$ git status
On branch main
nothing to commit, working tree clean

# 2️⃣ 添加到索引 (添加到索引中的修改的内容被撤销)
$ cat >> git-reset-hard.md
## git reset --hard
the mode of hard will remove working tree and index.
$ git add git-reset-hard.md
# 第2次 git reset --hard
$ git reset --hard
HEAD is now at 2f1ffeb add git-reset-hard.md file (add到索引的文件被删除了)
$ git status
On branch main
nothing to commit, working tree clean

# 3️⃣ 提交到对象库(提交到对象库的不会被撤销)
$ cat >> git-reset-hard.md
## git reset --hard
the mode of hard will remove working tree and index.
$ git add git-reset-hard.md
$ git commit -a -m 'modify git-reset-hard.md file'
# 第3次 git reset --hard
$ git reset --hard
HEAD is now at b128c80 modify git-reset-hard.md file(提交到对象库的不会被删除)
$ git status
On branch main
nothing to commit, working tree clean
2.9.2 commit 参数
mode(–mixed)默认值
# 新增文件并提交到对象库
$ echo 'add git-reset-HEAD-1.md' > git-reset-HEAD-1.md
$ git add git-reset-HEAD-1.md
$ git commit -m 'add git-reset-HEAD-1.md file'

# 回退到上个提交 commit(上次提交的内容又回到工作区,可继续通过 add/commit 到对象库)
$ git reset HEAD~1
$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	git-reset-HEAD-1.md
mode(–soft)
# 新增文件并提交到对象库
$ echo 'add git-reset-HEAD-1.md' > git-reset-HEAD-1.md
$ git add git-reset-HEAD-1.md
$ git commit -m 'add git-reset-HEAD-1.md file'

# 回退到上个提交 commit(上次提交的内容又回到暂存区,可继续通过 commit 到对象库)
$ git reset --soft HEAD~1
$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   git-reset-HEAD-1.md
mode(–hard)
# 新增文件并提交到对象库
$ echo 'add git-reset-HEAD-1.md' > git-reset-HEAD-1.md
$ git add git-reset-HEAD-1.md
$ git commit -m 'add git-reset-HEAD-1.md file'

# 回退到上个提交 commit(上次提交的内容从工作区和暂存区全部删除)
$ git reset --hard HEAD~1
HEAD is now at b128c80 modify git-reset-hard.md file
$ git status
On branch main
nothing to commit, working tree clean

3、Git Branch

git branch 是用于创建、删除以及查看分支信息

3.1 查看分支

列出当前 git 工程的所有分支

# 列出所有分支
$ git branch
* main

# 列出所有分支详情
$ git branch -v (--verbose)
* main b128c80 modify git-reset-hard.md file

说明

  • main:表示分支名称
  • *:星号标识当前的分支

3.2 新建分支

# 新建 test 分支
$ git branch test

# 查看分支
$ git branch
* main
  test

3.3 切换分支

  • 方式一:checkout
# 切换到 test 分支
$ git checkout test
Switched to branch 'test'

# 查看分支
$ git branch
  main
* test
  • 方式二:switch
# 切换到 main 分支
$ git switch main
Switched to branch 'main'

# 查看分支
$ git branch
* main
  test
  • 方式三(推荐):switch
# 新建并切换到uat分支
$ git switch -c uat
Switched to a new branch 'uat'

$ git branch
  main
  test
* uat
  • 方式四(切换到上个分支):switch
# 切换到 main
$ git switch main
Switched to branch 'main'

# 切换到上个分支
$ git switch -
Switched to branch 'uat'

# 多次使用可在 main 和 uat 分支来回切换
$ git switch -
Switched to branch 'main'

3.4 删除分支

# 1️⃣ 删除 test 分支 (test 分支没有需要合并到 main 分支内容时可直接删除)
$ git branch -d test
Deleted branch test (was b128c80).

# 2️⃣ 新建 test 分支,且增加一个提交
$ git switch -c test
$ echo 'add test.md file in test branch' > test_branch.md
$ git add test_branch.md
$ git commit -m 'add test.md file'

# 先切换到 main 分支
$ git switch main 
# 再次删除 test 分支(不能删除当前分支)
$ git branch -d test
error: The branch 'test' is not fully merged.
If you are sure you want to delete it, run 'git branch -D test'.

说明:test 分支有未 merge 到 main 分支的 commit,所以删除报错,要删除有 2 种方式

  • 合并到 main 后删除
# test 分支合并到 main
$ git mrege test
Updating b128c80..495a531
Fast-forward
 test_branch.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 test_branch.md

 # 删除 test 分支(成功删除)
 $ git branch -d test
 Deleted branch test (was 495a531).
  • 强制删除分支:git branch -D test
# 新建 test 分支
$ git switch -c test

# 强制删除
$ git branch -D test
Deleted branch test (was c9d4915).

3.5 修改分支

# 移动或重命名分支(test -> test-new)
$ git branch -m test test-new
$ git branch
* main
  test-new
  uat

# 复制分支(test-new -> test-new-copy)
$ git branch -c test-new test-new-copy
$ git branch
* main
  test-new
  test-new-copy
  uat

3.6 合并分支

# 创建 feature 分支
$ git switch -c feature-add-readme

# 新建一个提交
$ echo '# Git add new Feature' > README.md
$ git add README.md
$ git commit -m 'add readme.md file'

# feature 分支合并到 main 分支
$ git switch main
$ git merge feature-add-readme
Updating b128c80..d3ecec6
Fast-forward
 README.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

说明:

  • 分支合并并不总是一帆风顺的,总会出现冲突,此时可以通过 git diff 查看差异并修正,修正后可通过 **git merge --continue **继续合并。如果不想再合并,可通过 **git merge --abort **放弃本次合并
  • 如果合并分支差异很多,建议使用 GUI 工具进行查看差异并合并

3.7 分支隐藏变化内容

工作中经常情况是,正在某个分支开发需求,但是突然线上有问题需要紧急修复 bug。此时可以用过stash指令,将已修改的内容保存后,再去切换到主分支进行修复 bug。

# test分支正开发需求(添加一个文件,修改一个文件)
$ echo 'add test-stash.md file' > test-stash.md
$ git add test-stash.md
$ cat >> README.md
working on feature readme.md file
$ git status
On branch test
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   test-stash.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

# 隐藏修改的内容
$ git stash
Saved working directory and index state WIP on test: d3ecec6 add readme.md file
# 查看隐藏的修改内容
$ git stash list
stash@{0}: WIP on test: d3ecec6 add readme.md file

# 切换到 main 分支修复 bug
$ git switch main
------on-fix-bug------

# 切换到 test 分支
$ git switch -

# 恢复隐藏的内容,继续开发新需求
$ git stash pop
On branch test
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   test-stash.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

# 删除隐藏的内容
Dropped refs/stash@{0} (2e5f54e16dbe17da875c2a542edacd64f0532a89)

# 查看隐藏列表
$ git stash list
// 空内容

stash 其他参数
数据准备:

# 将上面的内容继续隐藏
$ git stash
Saved working directory and index state WIP on test: d3ecec6 add readme.md file

# 添加隐藏
$ echo 'add test-stash-2.md file' > test-stash-2.md
$ git add test-stash-2.md
$ git stash
Saved working directory and index state WIP on test: d3ecec6 add readme.md file
# 添加隐藏
$ cat >> test-stash-2.md
modify test-stash-2.md file
$ git add test-stash-2.md
$ git stash
Saved working directory and index state WIP on test: d3ecec6 add readme.md file

# 查看
$ git stash list
stash@{0}: WIP on test: d3ecec6 add readme.md file
stash@{1}: WIP on test: d3ecec6 add readme.md file
  • drop:删除一条隐藏的内容
# 删除指定 stash
$ git stash drop stash@{0}
Dropped stash@{0} (db32a1ec419ad2b74bffe23755102e146f9d170a)

# 查看
$ git stash list
stash@{0}: WIP on test: d3ecec6 add readme.md file
  • clear : 移除所有已隐藏的内容
# 添加隐藏
$ echo 'add test-stash-3.md file' > test-stash-3.md
$ git add test-stash-2.md
$ git stash
Saved working directory and index state WIP on test: d3ecec6 add readme.md file

# 查看
$ git stash list
stash@{0}: WIP on test: d3ecec6 add readme.md file
stash@{1}: WIP on test: d3ecec6 add readme.md file

# 清空所有 stash
$ git stash clear

# 查看
$ git stash list
// 空内容

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1693629.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

node.js —— 解读http模块

目录 http模块&#xff1a; http模块的引入&#xff1a; 创建web服务器的基本步骤&#xff1a; web服务器的一些基本属性&#xff1a; 上述知识汇总案例&#xff1a; http模块&#xff1a; http模块的引入&#xff1a; const http require (http) 创建web服务器的基本步骤…

数据可视化每周挑战——全国星巴克门店数据可视化

这是我国星巴克门店的位置&#xff0c;营业时间等数据。 1.导入需要用的库&#xff0c;同时设置绘图时用到的字体&#xff0c;同时防止绘图时负号无法正常显示的情况。 import pandas as pd from pyecharts.charts import Bar,Map,Line,Pie,Geo from pyecharts import option…

iBarcoder for Mac v3.15.1中文激活版:让条形码生成变得如此简单

在现代社会&#xff0c;条形码无处不在&#xff0c;从超市商品到物流包裹&#xff0c;都离不开它的身影。iBarcoder for Mac作为一款简单易用的条形码生成软件&#xff0c;让条形码的生成变得如此简单。 iBarcoder for Mac v3.15.1中文激活版下载 无论你是需要为商品添加条形码…

springboot打包目录解析

一、引言 Java开发中我们使用最多的便是spring框架&#xff0c;比如springboot应用。微服务模式下&#xff0c;每个服务都是一个springboot应用&#xff0c;都会被打包成一个可执行jar包。那么我们有多少人尝试去了解过这个可执行jar到底是什么&#xff1f;它的结构是什么样的…

论文阅读--CLIPasso

让计算机把真实图片抽象成简笔画&#xff0c;这个任务很有挑战性&#xff0c;需要模型捕获最本质的特征 以往的工作是找了素描的数据集&#xff0c;而且抽象程度不够高&#xff0c;笔画是固定好的&#xff0c;素描对象的种类不多&#xff0c;使得最后模型的效果十分受限 之所以…

算法之背包问题

可分的背包问题是可以用贪心法来解决&#xff0c;而0-1背包问题通常使用动态规划方法来解决。 可分背包问题&#xff1a; 在可分背包问题中&#xff0c;物品可以被分割&#xff0c;您可以取走物品的一部分以适应背包的容量。这里的关键是物品的价值密度&#xff0c;即单…

GNSS中的多路径效应原理及计算方法

1 多路径效应原理 图1 多路径效应原理图 2 计算方法 如需原文&#xff0c;可加多源融合定位与智能控制讨论群获取,QQ群号&#xff1a;51885949

JAVAEE之线程(10)_线程池、线程池的创建、实现线程池

一 线程池 1.1为什么要有线程池&#xff1f; 线程池顾名思义是由多个线程所组成&#xff0c;作用就是减少线程的建立与销毁&#xff0c;与数据库连接池相同概念&#xff0c;为了减少连接与释放&#xff0c;从而降低消耗提升效率。 1.2 线程池的优势 总体来说&#xff0c;线程…

Milvus Cloud 非结构化数据平台

从技术面来看,向量数据库底座自然而然向外延伸的产品包含: 1)向量提取,从非结构化数据中提取向量,这是向量数据库上游的工作,十分重要; 2)模型选择,选择正确的模型,能够更精准、更高质量地提取向量; 3)映射管理,即管理数据的本体和数据的语义层之间的映射,在…

设计模式之创建型模式---原型模式(ProtoType)

文章目录 概述类图原型模式优缺点优点缺点 代码实现 概述 在有些系统中&#xff0c;往往会存在大量相同或者是相似的对象&#xff0c;比如一个围棋或者象棋程序中的旗子&#xff0c;这些旗子外形都差不多&#xff0c;只是演示或者是上面刻的内容不一样&#xff0c;若此时使用传…

【spring】@RequestBody注解学习

RequestBody介绍 RequestBody 是 Spring Framework 中的一个注解&#xff0c;用于将 HTTP 请求的正文绑定到处理方法的参数上。这个注解通常用于处理 POST 或 PUT 请求&#xff0c;这些请求通常包含 JSON 或 XML 格式的数据。 RequestBody 将 HTTP 请求的正文内容转换成指定的…

前端vue项目遇到的问题01——那些初级问题

前端vue项目遇到的问题01——那些初级问题 1. npm install 问题1.1 依赖冲突1.1.1 详细问题1.1.2 报错原因1.1.3 解决问题1.1.3.1 方式1——无视冲突1.1.3.1 方式2——更换依赖版本 1.2 nodejs版本问题1.3 node版本正确的情况&#xff08;audit问题&#xff09;&#xff08;这个…

OpenH264 编解码器介绍

思科 思科系统&#xff08;英语&#xff1a;Cisco Systems, Inc.&#xff09;是一间跨国际综合技术企业&#xff0c;总部设于加州硅谷&#xff1b;思科开发、制作和售卖网络硬件、软件、通信设备等高科技产品及服务&#xff0c;并透过子公司&#xff08;例子有OpenDNS、Webex、…

【C语言】整型提升与char取值范围

整型提升介绍 C语言中整型算术运算总是至少以缺省&#xff08;默认&#xff09;整型类型的精度来进行的。为了获得这个精度&#xff0c;表达式中字符、短整型操作数在使用前被转换为普通整型。而这个过程是悄悄发生的。 整型提升的意义&#xff1a; 表达式的整型运算要在CPU…

小米财报:业绩远超预期,汽车推着手机跑!

随着一季度财报陆续出炉&#xff0c;企业间的分化越来越明显。 新环境下&#xff0c;很多公司都陷入停滞时&#xff0c;去讨论“掉队”已经没有多少意义&#xff0c;现在真正值得我们关注的&#xff0c;是那些在逆风情况下&#xff0c;还能“领先”的企业。毫无疑问&#xff0…

小程序主体变更是通过迁移吗?是需要2个小程序吗?

小程序迁移变更主体有什么作用&#xff1f;好多朋友都想做小程序迁移变更主体&#xff0c;但是又不太清楚具体有啥用&#xff0c;今天我就来详细说说。首先&#xff0c;小程序迁移变更主体最重要的作用就是可以修改主体。比如你的小程序原来是 A 公司的&#xff0c;现在 A 公司…

2024-5-9-从0到1手写配置中心Config之@ConfigurationProperties热更新

在PropertySourcesProcessor中&#xff0c;需要通过http从config-server获取配置。 使用ConfigMeta包装服务信息 在MidnightConfigService接口中添加默认实现类 继承MidnightRepositoryChangeListener接口&#xff1b;获取默认的MidnightRepository&#xff1b;创建MidnightCo…

12306技术内幕

公司内部做的一次技术分享 文章目录 12306的成就12306系统特点12306系统难点解决思路产品角度技术角度余票库存的表如何设计&#xff1f; 抢票软件推荐巨人的肩膀 对于未公开的技术部分&#xff0c;只能结合已公开的信息&#xff0c;去做大胆的猜想。 本文提到的一些解决方案&…