初学者必须知道的Git命令!必备知识

作者 : IT 大叔 本文共1837个字,预计阅读时间需要5分钟 发布时间: 2020-09-23

配置Git

# list all the configured values
git config --list 

# Set username & email for git globally
git config --global user.name "Progressive Programmer"
git config --global user.email "progressive@gmail.com"

# Set committer name & email for git
git config --global committer.name "Programmer"
git config --global committer.email "programmer@gmail.com"

创建一个新的仓库

# Create a new folder and initialize git repo
git init name  

# Clone a remote repo in your local system
git clone url_of_repo 

将文件/文件夹添加到暂存区

# Adds mentioned file/folder to the staging area
git add hello.py 

# Adds all the files and folders in the current directory 
git add . 

# Opens the file and let you choose 
the portion to be added for next commit  
git add -p hello.py

提交变更

# Commit a snapshot of staged changes
git commit  

# Commit a snapshot of changes in the working directory. 
git commit -a

# Shortcut for commit with a commit message 
git commit -m "commit message"

Git分支

# Create a new branch
git branch crazy_experiment

# List all branches 
git branch
# List both remote and local branches   
git branch -a
# List only branches that match the pattern mentioned 
git branch --list  'pattern here'

开关| 删除| 重命名分支


# Move to different branches
git checkout branch_name
git switch  branch_name

# Shortcut to create a new branch and switch to the branch  
git switch -c  new_branch_name
git checkout -b  new_branch_name 

# Delete the given branch 
git branch -d  trash
# Force delete the given branch 
git branch -D  trash

# Rename the current branch 
git branch -m  new_name

合并分支


# Merge given branch name with the working branch
git merge  branch_name
# Continue merger after conflict resolution
git merge  --continue 

检查状态

# Shows the working tree status
git status  

# Shows status of working tree in a short format 
git status --short

# Shows status of branch in a short format 
git status --branch

远程仓库

# Lists remote repo name and url(fetch/push) 
git remote -v

# Add a remote repository with local repository 
git remote add origin url_remote_repo

# Remove the remote repo with given name
git remote remove repo_name

# Rename the remote repo with given name
git remote rename old_name new_name

# Updates remote repo with local repo 
git push 

我希望这可以帮助!!

您最喜欢的git命令是哪个?

免责声明:
1. 本站资源转自互联网,源码资源分享仅供交流学习,下载后切勿用于商业用途,否则开发者追究责任与本站无关!
2. 本站使用「署名 4.0 国际」创作协议,可自由转载、引用,但需署名原版权作者且注明文章出处
3. 未登录无法下载,登录使用金币下载所有资源。
IT小站 » 初学者必须知道的Git命令!必备知识

常见问题FAQ

没有金币/金币不足 怎么办?
本站已开通每日签到送金币,每日签到赠送五枚金币,金币可累积。
所有资源普通会员都能下载吗?
本站所有资源普通会员都可以下载,需要消耗金币下载的白金会员资源,通过每日签到,即可获取免费金币,金币可累积使用。

发表评论