GIT Referencia Rápida

GIT Quick Reference (GIT Referencia Rápida)

Initial Configuration

Configuración inicial

Configure username: git config --global user.name "Your Name" 配置用户名:git config --global user.name "你的名字"

Configure email address: git config --global user.email "your@email.com" 配置电子邮箱地址:git config --global user.email "你的邮箱@email.com"


Basic Commands

基础命令

Initialize a new repository: git init 初始化新仓库:git init

Clone an existing repository: git clone <repository URL> 克隆现有仓库:git clone <仓库地址>

Add changes to the staging area: git add <file name> 将更改添加到暂存区:git add <文件名>

Commit changes: git commit -m "Commit message" 提交更改:git commit -m "提交信息"

Check repository status: git status 查看仓库状态:git status

View commit history: git log 查看提交历史:git log


Working with Branches

分支操作

Create a new branch: git branch <branch name> 创建新分支:git branch <分支名>

Switch to a specific branch: git checkout <branch name> 切换到指定分支:git checkout <分支名>

Merge a branch into the current branch: git merge <branch name> 将分支合并到当前分支:git merge <分支名>

Delete a branch: git branch -d <branch name> 删除分支:git branch -d <分支名>


Collaboration

协作

Add a remote repository: git remote add <repository name> <repository URL> 添加远程仓库:git remote add <仓库名> <仓库地址>

Fetch changes from a remote repository: git pull <repository name> <branch name> 从远程仓库获取更改:git pull <仓库名> <分支名>

Push changes to a remote repository: git push <repository name> <branch name> 将更改推送到远程仓库:git push <仓库名> <分支名>


Undoing Changes

撤销更改

Discard uncommitted changes: git checkout -- <file name> 丢弃未提交的更改:git checkout -- <文件名>

Undo the last commit: git revert HEAD 撤销最后一次提交:git revert HEAD

Revert a specific commit: git revert <commit hash> 回滚特定提交:git revert <提交哈希值>

Remove local changes and commits: git reset --hard HEAD 删除本地更改和提交:git reset --hard HEAD


Further Reading

延伸阅读

Check out the other articles in this series: 查看本系列的其他文章:

  • GIT: GIT
  • GIT Referencia Rápida (GIT Quick Reference)
  • GIT Cheatsheet