git init:初始化一个新的 Git 仓库。
git init
git clone:克隆远程仓库到本地。
git clone <repository_url>
git add:将文件添加到暂存区。
git add <file_name>
git commit:将暂存区中的文件提交到本地仓库。
git commit -m "Commit message"
git push:将本地仓库的变更推送到远程仓库。
git push origin <branch_name>
git pull:从远程仓库拉取最新的变更并合并到本地仓库。
git pull origin <branch_name>
git branch:管理分支。
git branch # 列出所有分支 git branch <branch_name> # 创建新分支 git branch -d <branch_name> # 删除分支
git checkout:切换分支或还原文件。
git checkout <branch_name> # 切换分支 git checkout -- <file_name> # 还原文件到最近一次提交的状态
git merge:合并指定分支到当前分支。
git merge <branch_name>
git status:查看仓库当前的状态。
git status
git log:查看提交历史。
git log
git remote:管理远程仓库。
git remote -v # 查看远程仓库列表 git remote add <name> <url> # 添加远程仓库
git reset:重置当前分支的 HEAD 到指定状态。
git reset --hard <commit_hash> # 重置到指定提交
git stash:暂存当前工作目录的变更。
git stash # 暂存变更 git stash apply # 恢复暂存的变更
git tag:管理标签。
git tag # 列出所有标签 git tag <tag_name> # 创建新标签
这些是 Git 中常用的一些命令,覆盖了版本控制、分支管理、远程仓库操作等多个方面。