git用法

git - the simple guide - no deep shit!

工作区 -> 暂存区 -> 分支

git init                        # 初始化git, 在当前文件夹生成.git

git add .                    # 把所有文件添加到暂存区

git commit -m ''         # 把暂存区中的文件添加到成果区

git commit -am ''       # 相当于先执行了git add .

.gitignore文件指定哪些文件被排除在外

从暂存区中移除文件:

git rm --cached <file>

git 远程仓库格式

git@github.com:username/repository.git        SCP-like格式

git设置用户身份

git config --global user.name "Your Name"
git config --global user.email "Your Email"
git config --global https.proxy 127.0.0.1:7890
git config --global --list                        # 查看配置

远程仓库 git remote

git remote add origin <remote_repository_URL>     # 添加远程仓库

git push origin master                            # 上传到远程仓库

git pull origin master                            # 下载到本地仓库

git remote -v                                     # 查看远程仓库

branch

git branch                        # 查看本地分支
git branch -r                     # 查看远程分支
git branch <branch_name>          # 创建新分支

git branch -m <new_name>          # 重命名当前分支
git branch -d <name>              # 删除分支

git checkout <branch-name>        # 切换到新分支

git merge <name>                  # 将<name>合并到当前分支

git状态

git log                    # 之前的提交
git status                 # 当前状态

git reset --hard HEAD      # 回退到最近的commit
                             hard删除工作区和暂存区,mixed删除暂存区(默认),soft不删

git clean                  # 删除未被追踪的文件

.gitignore

!为例外
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

git多人合作 

git add .
git commit -m "message"
git pull --rebase            # 取消合并commit
git push    

linux上配置git服务器

服务器端

1. 创建git用户
sudo adduser git

2. 配置公钥
在/home/git/.ssh中创建authorized_keys
把公钥内容<ssh-rsa aaaaabsssa== comment>复制到authorized_keys
.ssh文件夹为700
authorized_keys为600

3. 创建文件目录
/srv/git/project.git

4. 创建git环境
在project.git文件夹中运行git init --bare

客户端

1. 在~/.ssh中配置私钥
config中Host为ipv4或域名

2. git clone git@<ipv4>:/srv/git/project.git

diff

用来查看差异

# 填入2个commit的哈希值
git diff <commit1> <commit2>

git漏洞

cve-2024-32002

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值