2024-10-18
假设你们正在一个团队中工作,每个成员都在不同的部分贡献代码。你作为项目经理想要确保所有人都能及时更新最新的代码库,并在做出重大更改之前保持最新状态。
初始化仓库
git init
git init .
添加文件到索引(暂存区)
git add <file1> <file2>
git add .
提交更改
git commit -m "Your commit message"
git reset --soft HEAD^ && git add .
创建新的分支
git checkout -b <branch-name>
git checkout <branch-name>
合并分支
git merge
): git merge <other-branch>
git tag <tag-name> && git push --tags
删除文件
rm <file>
git tag <tag-name> && git push --tags
列出暂存和未暂存的文件
git status
git ls-files --other --exclude-standard
获取远程仓库更新
git fetch origin <branch-name>
推送更改到远程仓库
git push origin <branch-name>
git push --force-with-lease <remote>/<branch> HEAD:<commit-hash>
删除本地分支
git branch -d <branch-name>
git branch -D <branch-name>
这个 Git 简便指南将提供一个有效的基础,帮助你管理前端项目的协作。记住,逐步提高项目的复杂性来改进它们。
通过熟练掌握这些 Git 命令,你可以有效地在团队项目中管理和协作,高效地管理代码,并确保所有成员都能快速更新到最新状态。 | Git 命令 | 功能描述 |
| --- | --- |
| git init
| 创建一个新的Git仓库 |
| git add <file>
| 将指定的文件暂存至索引 |
| git commit -m "Your message"
| 提交已暂存的更改,附上一条消息 |
| git checkout -b <branch-name>
| 从当前分支创建一个新分支并跳转到该分支 |
| git merge <other-branch>
| 将一个分支合并到另一个分支中 |
| git tag <tag-name>
| 标记特定提交 |
| git push --tags
| 推送新的标签到远程仓库 |
| git reset --soft HEAD^ && git add .
| 撤销对暂存区文件的修改,重新添加更改 |
| git branch -d <branch-name>
| 删除本地分支 |
| git branch -D <branch-name>
| 强制删除已删除的本地分支 |
| git push origin <branch-name>
| 将指定的本地分支推送到远程仓库 |
| git fetch origin <branch-name>
| 获取远程仓库中的更改并同步到当前分支 |
| git tag <tag-name> && git push --tags
| 在远程仓库中推送特定提交的标签 |
这些命令和描述提供了基本的 Git 工作流程,是团队协作管理和代码管理的基础。