---
title: "Git技巧"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/git-tips-and-tricks/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/03-软件工程与质量保障/CI-CD与质量保障/CI-CD工具链/Git技巧.md"
content_hash: 0ac5400fcaad3e91e9cb8fa419452f462884c2ff9591a7a34943d976572002e1
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# Git技巧

﻿# Git技巧

> 创建时间：2022/3/29 11:47

删除某次提交，回退到某次记录——不到万不得已不要这样做，这样会让本地和远程的相关内容都丢失。

git log // 查找要删除的前一次提交的 commit_id

git rebase -i commit_id // 将 commit_id 替换成复制的值

进入 Vim 编辑模式，将要删除的 commit 前面的 `pick` 改成 `drop`

$ git reset --hard HEAD^ 回退到上个版本

$ git reset --hard HEAD~3 回退到前3次提交之前，以此类推，回退到n次提交之前

$ git reset --hard commit_id 退到/进到 指定commit的sha码

强推到远程：

$ git push origin HEAD --force

Git配置代理

<https://zhuanlan.zhihu.com/p/390620901>

<https://imciel.com/2016/06/28/git-proxy/>

自动放弃本地修改并更新

cd /d %WORKINGCOPY_DIR%

git reset --hard

git checkout -b main origin/main

git pull origin main:main

​
