> git add README.md
> git commit -m "Adds a description to the repository"
[main bcbcbc] Adds a description to the repository
1 file changed, 2 insertions(+), 0 deletions(-)
> git push
Writing good commit messages is a key part of a maintainable project. A guide on writing commit messages can be found here.
Git Pull
当用户不希望自动合并到当前工作分支时,可以使用 git fetch
。
此命令从远程存储库检索历史记录或提交。当遥控器包含你没有的工作时,它将尝试自动合并。请参阅:docs/software/basic-programming/git-getting-started:Merging。
运行: git pull
Git Add
This command “stages” the specified file(s) so that they will be included in the next commit.
For a single file, run git add FILENAME.txt
where FILENAME.txt is the name and extension of the file to add.
To add every file/folder that isn’t excluded via gitignore,
run git add .
. When run in the root of the repository this command will stage every untracked, unexcluded file.
Git Commit
This command creates the commit and stores it locally. This saves the state and adds it to the repository’s history.
The commit will consist of whatever changes (“diffs”) were made to the staged files since the last commit.
It is required to specify a “commit message” explaining why you changed this set of files or what the change accomplishes.
运行:git commit -m "在此处输入消息"
Git Push
将本地更改上传 (推送) 到远程 (云)
运行: git push
Branches in Git are similar to parallel worlds. They start off the same, and then they can “branch” out into different varying paths. Consider the Git control flow to look similar to this.
在上面的示例中,main 被分支 (或复制) 到分支 Feature 1 中,并且有人查看了分支,从而创建了本地副本。然后,某人提交 (或上传) 了他们的更改,将其合并到分支功能 1 中。你正在将更改从一个分支 “合并” 到另一个分支。
创建一个分支
运行: git branch branch-name
,其中 branch-name 是要创建的分支的名称。新的分支历史将从当前的活动分支中创建。
输入一个分支
创建分支后,你必须进入分支。
运行: git checkout branch-name
其中 branch-name 是先前创建的分支。
In scenarios where you want to copy one branches history into another, you can merge them. A merge is done by calling git merge branch-name
with branch-name being the name of the branch to merge from. It is automatically merged into the current active branch.
It’s common for a remote repository to contain work (history) that you do not have. Whenever you run git pull
, it will attempt to automatically merge those commits into your local copy. That merge may look like the below.
However, in the above example, what if File A was modified by both branch Feature1 and Feature2? This is called a merge conflict. A merge conflict can be resolved by editing the conflicting file. In the example, we would need to edit File A to keep the history or changes that we want. After that has been done, simply re-add, re-commit, and then push your changes.
有时历史记录需要被重置,或者提交需要被撤消。这可以通过多种方式完成。
还原提交
你无法还原合并,因为 git 不知道应选择哪个分支或源。
要还原导致提交的历史记录,运行 git revert commit-id
。可以使用 git log
命令显示提交ID。
重设 Head 指针
强制磁头复位是一个危险的指令。此指令将永久删除目标之外的所有历史记录。请三思后行!
运行: git reset --hard commit-id
。
Forks
可以像处理分支一样处理 Fork。你可以将上游库 (原始存储库) 合并到本地库 (克隆存储库) 中。
克隆已存在的 “Repo”
在已经创建存储库并将其存储在远程服务器上的情况下,可以使用以下命令克隆该存储库:
git clone https://github.com/myrepo.git
where myrepo.git
is replaced with your git repo. If you follow this, you can skip to commits.
更新 Fork
添加上游: git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
确认通过以下方式添加了它:git remote -v
从上游进行 Pull 更改: git fetch upstream
将更改整合进 head: git merge upstream/upstream-branch-name
队伍 请勿 修改其机器人项目中随附的 .gitignore
文件,这一点非常重要。这可能导致下线部署无法正常工作。
一个 .gitignore
文件通常用作不使用 git add
自动提交的文件列表。此文件中列出的任何文件或目录都将 不提交。它们也不会显示为 git status.
Additional Information can be found here.
隐藏一个文件夹
只需添加包含要隐藏的文件夹的新行,并在末尾加正斜杠
例如: directory-to-exclude/
隐藏一个文件
用要隐藏的文件名添加新行,包括相对于存储库根目录的任何前缀目录。
例如:`` directory / file-to-hide.txt ``
例如:`` file-to-hide2.txt ``
附加的信息
在 git <https://git-scm.com/docs/gittutorial> 官方网站上可以找到更深入的教程。
可以在 git`flight 规则 <https://github.com/k88hudson/git-flight-rules/blob/master/README.md>`_ 存储库中找到纠正常见错误的指南。
版本 eb81fad2
.
利用 Sphinx 构建,使用的
由 Read the Docs 开发.