0%

Git常用命令

以下是Git常用操作的命令文档:

初始化仓库:

1
git init

添加文件:

1
git add [file]

提交代码:

1
git commit -m "commit message"

查看状态:

1
git status

查看历史记录:

1
git log

分支管理:

1
2
3
4
git branch [branch_name] # 创建分支
git checkout [branch_name] # 切换分支
git merge [branch_name] # 合并分支
git branch -d [branch_name] # 删除分支

撤销操作:

1
2
git reset [commit_id] # 撤销本地仓库的提交操作
git revert [commit_id] # 撤销远程仓库的提交操作

远程仓库操作:

1
2
3
4
git remote -v # 查看远程仓库信息
git clone [remote_repository_url] # 克隆远程仓库到本地
git push [remote_repository_name] [branch_name] # 推送代码到远程仓库
git pull [remote_repository_name] [branch_name] # 拉取远程仓库代码到本地

标签管理:

1
2
3
git tag # 查看标签信息
git tag -a [tag_name] -m "tag message" # 创建标签
git push [remote_repository_name] --tags # 推送标签到远程仓库

忽略文件:

1
2
3
# 创建.gitignore文件,添加需要忽略的文件或目录
touch .gitignore
echo "node_modules/" >> .gitignore

以上是Git常用操作的命令文档,可以帮助开发者更好地使用Git进行代码管理。