工作目录和本地存储库有什么区别? [英] What's the difference between working directory and local repository?

查看:113
本文介绍了工作目录和本地存储库有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的GitHub存储库。
我很困惑工作目录和本地存储库。
当我自己工作时,我的东西都在工作目录中。
但是在回购时,我应该检查我的东西。
但他们是同一件事吗?或者他们应该分开。
然后如何提交我的工作目录中的东西到我的本地回购。
如何提交我的本地仓库到远程仓库。
Git Bash如何做到这一点?
谢谢!

解决方案

工作目录是你的源文件在git控制下的目录(在所有目录的根目录下.git文件是当下)。
Git正在跟踪您的工作目录和本地存储库之间以及本地存储库和(远程存储库之一)之间的差异。



查看更改内容,请使用 $ git status

要将更改(编辑和/或新文件)提交到本地存储库,请使用 $ git add 然后 $ git commit

什么是承诺使用 $ git log

然后,如果您想将您的更改提交到远程存储库,请使用 $ git push

注意什么git命令是打印它通常包含建议做什么。

如果您正在使用GitHub,他们的帮助也很有用:推送到远程



良好的基本信息也是




FOR

例子:

假设你使用 $ git init 在JavaRepo目录中,并在那里用 $ git pull $ git clone 。然后JavaRepo应该包含.git文件(包括其他git虚线文件) - 您可以使用 $ ls -a 来检查它。 这些文件本身就是本地git仓库,并且不需要区分'工作目录'和'本地仓库'目录。



因此,开始使用JavaRepo中的文件:假设您更改了文件example.java并创建了新文件example2.java。在JavaRepo(或其任何子部分)中执行 $ git status 。它应该显示:'modified:example.java''未追踪文件:example2.java'



使用 $ git add example.java 将文件添加到临时区域,使用这些文件从目录中 $ git添加example2.java 命令。 (请注意, $ git add 既适用于已更改的文件,也适用于新文件。)

最后,通过 $ git commit -m示例更改(-m保留消息 - 对提交的注释)提交文件。 p>

$ git log 应显示此提交。


I've created a new GitHub repository. I'm quite confused by working directory and local repository. When working on my own, my stuff all resides on working directory. But when work with repo, I should check my stuff there. But are they the same thing? or should they be separate. Then how to commit my stuff in working directory to my local repo. How to commit my local repo to remote repo. How to do this by Git Bash? Thanks!

解决方案

Working directory is the directory with your source files under git control (in the root of all dirs under control .git file is present). Git is tracking the difference between your working directory and local repository, and between your local repository and (one of) remote repositories.

To see what was changed, use $ git status.

To commit your changes (edits and/or new files) to the local repository, use $ git add and then $ git commit.

To see what was committed use $ git log.

Then, if you want to commit your changed to the remote repository, use $ git push.

Pay attention to what git commands are printing, it often contain advice what to do.

If you are working with GitHub, their help is also useful: pushing to a remote.

Good basic information is also in atlassian site.


FOR EXAMPLE:

Suppose, you initiated your git repository with $ git init in JavaRepo dir and checkouted there the project with $ git pull or $ git clone. Then JavaRepo should contain .git file (among others git dotted files) - you can check it with $ ls -a. These files itself are the local git repository, and there is no need to distinguish 'working directory' and 'local repository' directory.

So, start working with files in JavaRepo: say you changed file example.java and created new file example2.java. Execute $ git status in JavaRepo (or in any its subdirs). It should show: 'modified: example.java', 'Untracked files: example2.java'.

Add your files to the staging area with $ git add example.java and $ git add example2.java commands from the directory with these files. (Notice that $ git add is both for changed and new files.)

And finally commit your files by $ git commit -m "example changes" (-m stays for message - comments to the commit).

$ git log should show this commit.

这篇关于工作目录和本地存储库有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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