简单的 GIT 命令序列 [英] Simple Sequence of GIT Commands

查看:26
本文介绍了简单的 GIT 命令序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了文档并在 Google 上搜索了一番,但没有真正简单的步骤可以将您的本地更改提交到 github.我编译了以下步骤,我只是想确保做正确的事情.如果我在本地更改了文件 foo.java:

<块引用>

  1. git status -s//会告诉我 foo.java 已经改变了

  2. git add foo.java//将把它添加到我的本地仓库

  3. git commit -m 我的修改"//提交到本地仓库

  4. git 标签v1.1"//创建一个标签

  5. git push --tags//最后,将本地提交移动到带有新标签的远程仓库.这将提示您输入密码.如果没有像第 4 步那样设置标签,那么只需

<块引用>

git 推送

就够了.对吧?

我只是想确保大多数用例的这些基本步骤是使用 github 所需的.我是 github 的新手,这些步骤对我有用,但要确保我没有犯任何根本性的错误.如果有任何遗漏的步骤,请发表评论.同样,我关心最通用的日常使用(例如,我并不真正关心分支等,我将根据需要学习).提前谢谢你.

解决方案

你的步骤很好.不过,要稍微挑剔一下评论:

关于步骤 (2) 和 (3) 的评论并不是思考正在发生的事情的最佳方式,我不相信.

2.git add foo.java//将它添加到我的本地仓库3.git commit -m "my changes"//提交到本地repo

将您的文件添加到本地存储库的步骤是git-commit.这就是为什么它被称为 commit;您提交对存储库的更改.git-add foofoo 添加到 staging areanot 添加到 repo 本身.

您的 git 存储库有三个区域",workingstagingrepository,如下图所示(图片取自 - 它有一大堆漂亮的图片和足够简单的语言,我可以理解它;)

I read the documentation and googled a good bit, but there is no real simple steps to be able to commit your local changes to github. I compiled the following steps and I just want to make sure am doing the right thing. If I changed a file foo.java locally:

  1. git status -s          //will show me that foo.java has changed

  2. git add foo.java     //will add it to my local repo

  3. git commit -m "my changes"      //commit to the local repo

  4. git tag "v1.1"       //create a tag

  5. git push --tags        //finally, move the local commit to the remote repo with the new tag. this will prompt for your password. if no tag is set as in step 4, then just

git push

is enough. right?

I am just trying to make sure that these basic steps for the most use cases is what is required to use github. I am brand new to github, and these steps are working for me, but want to make sure i am not making any fundamental mistake. Please comment if there are any missing steps. Again, am concerned about the most generic day-to-day use (like, am not really concerned about branches, etc. which I will learn on a need basis). Thank you in advance.

解决方案

Your steps are fine. To nit-pick slightly, though, about the comments:

The comments about step (2) and (3) are not the best way to think about what's happening, I don't believe.

2.git add foo.java     //will add it to my local repo
3.git commit -m "my changes"      //commit to the local repo

The step which "adds" your file to the local repository is git-commit. That's why it's called commit; you commit changes to the repository. git-add foo adds foo to the staging area, not to the repo itself.

Your git repository has three "areas", working, staging and repository, depicted here (image taken from the Pro Git book):

You make changes and work in the creatively named "working directory".

When you've made some changes, you want to prepare to make a commit. This is where the "staging area" comes into play. You "stage" the changes that you want to commit, and when you're happy with what the commit will look like, you commit the "staging area" to the "repository". [Note: in the man pages, this staging area is mostly referred to the index].

This allows you a lot of flexibility. You can stage all the changes since your last commit, or you can stage files individually, or you can stage parts of files. You can add and delete files from the staging area without losing changes or messing up the repositories history. That's what the git add and git rm commands do; they add from the working directory to the staging area, but they don't add directly into the repository. (Hopefully the image helps make the distinctions clear).

Your steps are fine. If you want to understand more about branching, commiting, manipulating commits and branches and whatnot, I'd recommend reading the Pro Git book - it's got a whole bunch of pretty pictures and language simple enough that I can understand it ;)

这篇关于简单的 GIT 命令序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆