我想改进我的工作流程,所以我决定自己使用git。
直到我的项目,在我的网络服务器上,我有2个文件夹,它们是prod和dev。
修改结束后,我同步了两个文件夹。
我试着像这样使用git:
// on my prod folder
$ git init
$ git add *
$ git commit -a
然后在父文件夹
$ git clone prod dev
像魅力一样工作我把我的dev文件夹作为完美的生产床 但是现在一旦我的修改成功,我就无法承诺。我怎样才能做到这一点?! THX
修改
这是我的网络服务器上的组织树:
home
|--git
|--.ssh
|--repositories
|-- myfirstrepo.git
|-- index.html
我想要实现的目标是/var/www
$ git clone /home/git/repositories/myfirstrepo.git
Initialized empty Git repository in /var/www/myfirstrepo_wc/.git/
我在
中获得了我的回购的克隆var
|--www
|--myfirstrepo_wc
|--index.html
现在我在/var/www/myfirstrepo_wc
然后
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: www/index.html
#
no changes added to commit (use "git add" and/or "git commit -a")
提交
$ git commit -a
[master d19749d] first commit from working copy
Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
然后想要拉到/home/git/repositories/myfirstrepo.git
$ git pull origin master
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 358 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /git/myfirstrepo.git
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/git/myfirstrepo.git'
答案 0 :(得分:0)
两个带有两个.git文件夹的文件夹意味着你有两个git存储库,你想要的是一个带有一个.git文件夹和两个分支的文件夹,“prod”用于生产,“dev”用于开发,并在两者之间进行更改“结账”你想看到的分支。一旦你有了这个,你就可以在dev完成更改之后将更改从dev变为prod,并且它们已经为prod做好了准备,而这并不理想,这是一个开始。 在你的情况下,你可以:
git branch dev
,这将创建一个名为dev的新分支,基于master(假设master = prod)git checkout dev
以转到开发分支git status
,您会发现已更改的文件已标记为此类。现在让我们假设您对开发中的更改感到满意,并希望将它们添加到master,
git checkout master
git pull dev
请记住,这只是为了让您开始使用git,尝试使用玩具存储库并使用补充工具。
答案 1 :(得分:0)
好的,我找到了解决方案:
$git remote add origin git@localhost:path/to/myfirstrepo.git
$git push origin master