【Git】项目管理笔记

在linux环境下

sudo apt-get install git

在centos环境下

sudo yum install git -y

查看git版本

git --version

设置全局git作者名

git config --global user.name "David"

设置全局email

git config --global user.email "123456@qq.com"

查看设置结果

git config user.name
git config user.email

本地电脑初始化

mkdir learntest
cd learntest
pwd # 查看目录地址

项目初始化git

git init

删除文件

rm -r file_name

克隆文件

git clone  url

然后username输入对应的email然后再输入password

git clone -b dev <repository_url>

查看分支数量

git branch -a | wc -l

查看分支

git branch -a

查看当前分支

git branch

docker报错

ERROR【docker】报错:Got permission denied while trying to connect to the Docker daemon socket at unix:///var/
需要使用root权限

ERROR docker pull mysql 报missing signature key错误
如果安装docker用的是yum install docker命令的话,下载下来的docker版本未旧版本,所有数字签名有问题
https://blog.csdn.net/Single_for_life/article/details/133653113

su root

https://www.php.cn/faq/506200.html
https://www.modb.pro/db/586199
https://www.bilibili.com/read/cv22443043/

.gitignore

推荐博客
使用.gitignore文件来定义需要忽略的文件或文件夹。有时候,我们希望某些文件不被提交到代码库中,例如编译生成的文件、日志文件等。
在Git中,可以使用.gitignore文件来指定要忽略的文件或文件夹。比如要在上传文件时忽略__pycache__文件夹,可以按照以下步骤操作:

  1. 在项目根目录下创建一个名为.gitignore的文件(如果尚不存在),将需要忽略的文件或文件夹加入到该文件中。
  2. 使用文本编辑器打开.gitignore文件。
  3. 每一行代表一个要忽略的文件或文件夹,可以使用通配符来匹配多个文件。在文件中添加以下行:
# Ignore __pycache__ folder
__pycache__

# Ignore compiled Python files
*.pyc

# Ignore log files
*.log

# Ignore build folder
build/

# 忽略所有以 .a 结尾的文件
*.a

# 不能忽略所有 lib.a 文件
!lib.a

# 仅仅忽略当前目录下的 TODO 文件
/TODO

# 忽略 build 目录下的所有文件
build/

# 仅仅忽略 doc 一个目录下的所有 .txt 文件
doc/*.txt

# 忽略 doc 目录下(包括子目录)的所有 .pdf 文件
doc/**/*.pdf

这将告诉Git忽略名为__pycache__的文件夹。
4. 保存并关闭.gitignore文件。

现在,当使用Git提交和上传您的代码时,__pycache__文件夹将不会包含在提交中。

请注意,.gitignore文件仅适用于未跟踪的文件。如果__pycache__文件夹已经被Git跟踪并提交到了版本控制中,您需要先从Git的跟踪中删除它。可以使用git rm -r --cached __pycache__命令来从Git的跟踪中删除该文件夹。然后,可以使用上述步骤将__pycache__添加到.gitignore文件中,以确保未来提交时不会再次包含它。

git log

git log你会看到一个提交历史的列表,每个提交都有一个独特的哈希值。
在这里插入图片描述

git reset

git reset --hard HEAD

运行完上述命令以后,所有本地分支的修改就会被放弃并回滚到最近一次提交的状态

git status

git ls-files

列出缓存区文件

git rm -r -f --cached

删除缓存区的跟踪文件

git rm -r --cached __pycache__

拉取仓库文件更新本地的项目

报错提示

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.

意味着有些远程的仓库修改没有添加到本地项目中

git pull origin master --allow-unrelated-histories

报错处理

! [rejected] master -> master (fetch first)

! [rejected] master -> master (fetch first) error: failed to push some refs to

解决方案:
强制push

 git push origin master -f

git@gitee.com: Permission denied (publickey).

推荐博客1
推荐博客2

error: remote origin already exists.

推荐博客

提示:当你在git push到GitHub的时候报错 出现error: remote origin already exists.
翻译过来呢就是 错误:远程源已经存在

解决方案

git remote -v #第一: 查看远程库的信息
git remote rm origin # 第二: 删除现有的远程仓库
git remote add origin + 远程仓库地址 # 第三: 建立新的远程仓库地址

相关推荐

  1. git项目管理

    2024-01-29 05:40:02       54 阅读
  2. vscode集成git管理项目

    2024-01-29 05:40:02       35 阅读
  3. 探索 Git:开源项目管理的利器

    2024-01-29 05:40:02       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-29 05:40:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-29 05:40:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-29 05:40:02       82 阅读
  4. Python语言-面向对象

    2024-01-29 05:40:02       91 阅读

热门阅读

  1. 一维数组的学习

    2024-01-29 05:40:02       57 阅读
  2. bridge

    2024-01-29 05:40:02       50 阅读
  3. sql总结(高阶用法)

    2024-01-29 05:40:02       53 阅读
  4. paddle 动态图命名重复问题

    2024-01-29 05:40:02       58 阅读
  5. 707.设计链表(力扣LeetCode)

    2024-01-29 05:40:02       56 阅读
  6. SpringBoot中实现阿里云OSS对象存储

    2024-01-29 05:40:02       52 阅读
  7. Spring Task 自定义定时任务类

    2024-01-29 05:40:02       50 阅读
  8. true friendship

    2024-01-29 05:40:02       50 阅读
  9. vue3使用特殊字符@、~代替路径src

    2024-01-29 05:40:02       64 阅读