简体   繁体   English

提交后Git不影响更改

[英]Git Does Not Affect Changes After Commit

This is my first time trying to work with version control. 这是我第一次尝试使用版本控制。 As I found one of the best solution is Git. 我发现最好的解决方案之一是Git。

I did almost everything correct and at least i got some problem or something like that. 我几乎做了所有正确的事情,至少我遇到了问题或类似问题。

Debian Machine. Debian机器。

/home/user/myProject/ / home / user / myProject /

git init --bare myproject.git

/var/www/clonedProject/ / var / www / clonedProject /

git clone /home/user/myProject/myproject.git
git add xxx.php
git commit -m "TEST"
git push origin master

but there is no changes in home/user/myProject. 但是home / user / myProject中没有任何更改。 I don't understand what is problem about, if there is problem or what i am doing wrong. 我不明白问题是什么,如果有问题或我做错了什么。

Git documentation Git文档

Thanks. 谢谢。

Here's a complete test run using your example (as close as reasonably possible, anyway). 这是使用您的示例进行的完整测试(无论如何,应尽可能合理地进行)。 You can see from this log that your commands should be working fine. 从该日志中可以看到您的命令应该可以正常工作。 If you get some different output, please share it with us so we can help you solve your real problem. 如果您得到不同的输出,请与我们分享,以便我们可以帮助您解决实际问题。 Step by step: 一步步:

  1. create some directories to work with for this example 创建一些用于此示例的目录

     $ mkdir bare $ mkdir clone 
  2. initialize a bare repo called myproject.git 初始化一个名为myproject.git的裸myproject.git

     $ cd bare/ $ git init --bare myproject.git Initialized empty Git repository in /example/bare/myproject.git/ 
  3. change to the clone directory and clone the repo we just created 转到clone目录并克隆我们刚刚创建的仓库

     $ cd ../clone $ git clone ../bare/myproject.git Cloning into 'myproject'... warning: You appear to have cloned an empty repository. done. 
  4. change directory into the new repo, then create, add, and commit a new file 将目录更改为新的仓库,然后创建,添加和提交新文件

     $ cd myproject/ $ touch xxx.php $ git add xxx.php $ git commit -m "TEST" [master (root-commit) 921786a] TEST 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 xxx.php 
  5. push this new commit back to origin (the bare repo we cloned from earlier) 将这个新提交推回原点(我们从之前克隆的裸仓库)

     $ git push origin master # push this new commit to origin Counting objects: 3, done. Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To /example/clone/../bare/myproject.git * [new branch] master -> master 
  6. go back to the bare repo and see if the commit is there 回到裸仓库,看看提交是否存在

     $ cd ../../bare/myproject.git/ $ git log commit 921786a20f3e7e0d17eec65450472b54bf3d7c56 Author: Carl Norum <carl@someplaceorother.com> Date: Wed Jul 3 08:00:31 2013 -0700 TEST 
  7. It is, so everything worked fine. 是的,所以一切正常。

your changes have been copied into the database in /home/user/myProject/myproject.git . 您的更改已复制到/home/user/myProject/myproject.git的数据库中。 they will not be automatically distributed to all other clones. 它们不会自动分发到所有其他克隆。

to see them in home/usr/myProject you have to make this folder a clone of the repository as well and issue a git pull . 要在home/usr/myProject看到它们,您还必须使此文件夹也成为存储库的克隆并发出git pull it's not a good idea to have the "bare" repository within the project itself. 在项目本身中包含“裸露”存储库不是一个好主意。

instead you should probably use a separate git repository for all your "bare" repos. 相反,您可能应该对所有“裸露”存储库使用单独的git存储库。 you then push changes from a clone "repositoryA" to a central "bare" repository, and pull the changes from that central repository into another clone "repositoryB" 然后push更改从克隆“ repositoryA” push送到中央“裸”存储库,然后pull更改从该中央存储库拉到另一个克隆“ repositoryB”

$ cd ~
$ mkdir git
$ git init --bare git/myproject.git
$ cd git clone git/myproject myProject
$ ls
git/
myProject/
$ cd myProject/
$ ls
$ cd /var/www/clonedProject/
$ git clone /home/user/git/myproject.git
$ ls
myproject
$ cd myproject
$ touch xxx.php
$ ls
xxx.php
$ git add xxx.php
$ git commit -m "TEST"
$ git push origin master
$ cd ~/myProject
$ ls
$ git pull
$ ls
xxx.php
$

git itself is a "distributed" version control system, which means that the notion of a central repository is, well, inadequate. git本身是一个“分布式”版本控制系统,这意味着中央存储库的概念还不够完善。 it means, that there is not a single server, but can be any number of "remote" servers, including none. 这意味着,没有单个服务器,但是可以是任何数量的“远程”服务器,包括没有。 however, if you have multiple clones of a single repository, it is usually advisable to have at least one shared "remote", that is only accessed via git pull and git push . 但是,如果您有一个存储库的多个克隆,通常建议至少有一个共享的“远程”, 只能通过git pullgit push访问。 in theory you can clone a non-bare repository (that is: a working directory under git control) directly, but it is usually troublesome to push back to such a repository - mainly because you create a hierarchy of access rights. 从理论上讲,您可以直接克隆一个非裸仓库(即git控制下的工作目录),但是将其push回这样的仓库通常很麻烦-主要是因为您创建了访问权限的层次结构。

This might be a very good tutorial to get you started. 这可能是一个很好的入门指南。 Tutorial 讲解

Try git commit -a -m "TEST" 尝试git commit -a -m“ TEST”

Have you made a connection between your lokal repo and the remote repo? 您是否已在lokal存储库和远程存储库之间建立连接?

Try: git remote add origin /home/user/myProject/ 尝试: git remote add origin / home / user / myProject /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM