常见git命令

Git Commands

A list of my commonly used Git commands

If you are interested in my Git aliases, have a look at my .bash_profile, found here: https://github.com/joshnh/bash_profile/blob/master/.bash_profile

Getting & Creating Projects

CommandDescription
git initInitialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].gitCreate a local copy of a remote repository

Basic Snapshotting

CommandDescription
git statusCheck status
git add [file-name.txt]Add a file to the staging area
git add -AAdd all new and changed files to the staging area
git commit -m "[commit message]"Commit changes
git rm -r [file-name.txt]Remove a file (or folder)

Branching & Merging

CommandDescription
git branchList branches (the asterisk denotes the current branch)
git branch -aList all branches (local and remote)
git branch [branch name]Create a new branch
git branch -d [branch name]Delete a branch
git push origin --delete [branch name]Delete a remote branch
git checkout -b [branch name]Create a new branch and switch to it
git checkout -b [branch name] origin/[branch name]Clone a remote branch and switch to it
git checkout [branch name]Switch to a branch
git checkout -Switch to the branch last checked out
git checkout -- [file-name.txt]Discard changes to a file
git merge [branch name]Merge a branch into the active branch
git merge [source branch] [target branch]Merge a branch into a target branch
git stashStash changes in a dirty working directory
git stash popPopup first stash on cache stack changes to working directory & remove corresponse cache
git stash applyPopup all stash on cache stack changes to working directory & do not remove stashes that at the stack
git stash clearRemove all stashed entries

Sharing & Updating Projects

CommandDescription
git push origin [branch name]Push a branch to your remote repository
git push -u origin [branch name]Push changes to remote repository (and remember the branch)
git pushPush changes to remote repository (remembered branch)
git push origin --delete [branch name]Delete a remote branch
git pullUpdate local repository to the newest commit
git pull origin [branch name]Pull changes from remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].gitAdd a remote repository
git remote set-url origin ssh://git@github.com/[username]/[repository-name].gitSet a repository’s origin branch to SSH

Inspection & Comparison

CommandDescription
git logView changes
git log --summaryView changes (detailed)
git diff [source branch] [target branch]Preview changes before merging
Git 是一种分布式版本控制系统,用于管理源代码的历史记录、协作开发等任务。下面是一些常见Git 命令及其用途: ### 初始化仓库 ```bash git init ``` **功能**:创建一个新的本地 Git 版本库。 --- ### 克隆远程仓库 ```bash git clone <url> ``` **功能**:从指定 URL 地址克隆一个现有的远程仓库到本地。 --- ### 查看状态 ```bash git status ``` **功能**:查看当前工作目录的状态(如哪些文件已修改但未提交)。 --- ### 添加更改到暂存区 ```bash git add <file> 或 git add . ``` **功能**:将单个文件或所有改动添加到暂存区域(staging area),准备下一步提交。 --- ### 提交更改 ```bash git commit -m "描述信息" ``` **功能**:把暂存区的内容正式保存至本地分支,并附带一条简短说明。 --- ### 检查历史记录 ```bash git log ``` **功能**:展示所有的提交历史,默认按时间倒序排列;可以配合选项简化显示内容,例如 `--oneline`。 --- ### 切换分支 / 创建新分支并切换 ```bash git checkout <branch_name> # 或者更推荐的方式(现代语法) git switch <branch_name> git branch <new_branch_name> # 然后再切过去 git checkout <new_branch_name> # 同样可以用这个命令一步完成建+转动作 git switch -c <new_branch_name> ``` **功能**:在已有分支间跳转或者新建某个新的分支同时立即转移到那个上面去操作了。 --- ### 远程同步 (推送/拉取) #### 推送更新后的代码到服务器上对应的远端分支里 ```bash git push origin <branch_name> ``` #### 获取最新版资源合并进来保持一致 ```bash git pull origin <branch_name> ``` --- ### 解决冲突及忽略特定规则配置 当多人编辑同一段落产生分歧需要手动修正完再标记解决完毕才能继续后续流程: ```bash git merge --continue # 完成合并过程 # 若要让系统自动忽略掉某些类型的变动则可通过设置全局 .gitignore 文件实现批量屏蔽效果。 *.log __pycache__/ ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微个日光日

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值