Git基本工作流程 [英] Git basic workflow

查看:105
本文介绍了Git基本工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

git push error'[remote rejected] master - > master(分支目前已检出)'


我是Git的新手,尝试将其用于本地grails项目。

我遵循的步骤:


  1. 创建grails项目 li>
  2. 转至项目目录并 git init

  3. 添加项目中的所有文件区域和承诺。

  4. 存储库中的git状态提供以下信息:

      BXX @ BXX-PC / c / Work / Grails / projects / yyy / tables(master)
    $ git status
    在分支主机上
    无需提交(工作目录清理)


  5. 尝试将其保留为主分支,通过克隆回购库进行更改,稍后将更改推回。对于那个


  6. 在我的IDE中,签出项目(IntelliJ)。这实际上是将项目克隆到另一个目录。

  7. 进行更改并提交项目

  8. 将本地更改推送至主。

      15:41:56.249:git push -v origin master 
    推送到c:/ Work / Grails / projects / xxx / tables
    remote:error:拒绝更新签出分支:refs / heads / master
    remote:error:默认情况下,更新非裸仓库中的当前分支
    远程:错误:被拒绝,因为它会使索引和工作树不一致
    remote:error:与你推送的内容相同,并且需要'git reset --hard'来匹配
    remote:error:the工作树头。


克隆的回购状态是

  $ git status 
#分支大师
#你的分支在1次提交之前领先于'origin / master'。
$
没有提交(工作目录干净)

请帮助我理解这一点。是否有更好的工作流程要遵循。我可以通过Intellij初始化回购,并尝试在主分支上工作。仍然不知道上面有什么错。



谢谢。 首先,你不需要克隆你的本地仓库。您可以使用分支来将开发划分到同一个存储库中。



Git是分布式VCS,如果您在Subversion或CVS之前有过使用经验,则需要更改。



Git非常灵活,您可以使用不同的工作流程。克隆存储库对于团队工作而言更为必要,而不是用于本地开发(恕我直言)。



分支是您的一个很好的选择。



请参阅。我们为您的存储库的 master 分支设置生产就绪代码。我们为开发创建另一个分支:

  $ git checkout -b开发主

现在您正在开发开发分支。



您可以针对每个要开发的功能使用不同的分支。



假设您想要实现一些新功能,您需要创建一个新分支:

  $ git checkout -b newfeature development 

现在您可以使用您的代码,添加文件,提交等。



接下来,您需要合并新开发的功能到开发分支:

  $ git add。 
$ git commit -m我对新功能的最新修改
$ git checkout development
$ git merge newfeature

现在,您的 newfeature 分支中的新代码合并到开发分支中。

在您确定开发分支中的代码获得某个里程碑时,将来有一段时间,您可以将开发中的所有更改合并到 master 分支。



这是一个非常基本的工作流程,它可以为许多分支机构提供帮助。

我现在给你建议:阅读更多关于git,分支,存储的信息(对于快速修复非常非常有帮助)。在过了一段时间之后,您将会使用git获得巨大的努力。



祝您好运。


Possible Duplicate:
git push error '[remote rejected] master -> master (branch is currently checked out)'

I am new to Git and trying to use it for a local grails project.
The steps I followed:

  1. create the grails project
  2. go to the project directory and git init
  3. Add all the files in the project in staging area and commit.
  4. The git status at the repo gives the below message

    BXX@BXX-PC /c/Work/Grails/projects/yyy/tables (master)
    $ git status
    # On branch master
    nothing to commit (working directory clean)
    

  5. Trying to keep it as the master branch, make the changes by cloning the repo, and later push the changes back. For that

  6. In my IDE, checkout the project (IntelliJ).This actually clone the project to another dir.
  7. Make the changes and commit the project
  8. Push the local changes to master.

    15:41:56.249: git push -v origin master
    Pushing to c:/Work/Grails/projects/xxx/tables
    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. 
    

The cloned repo status is

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

Please help me with understanding this. Is there a better workflow to follow. I may be able to initialize the repo through Intellij, and try to work on the main branch. Still not sure what is wrong above.

thank you.

解决方案

First of all, you do not need to clone your local repository. You can use branches to divide development in the same repository.

Git is a Distributed VCS, and if you have experience with Subversion or CVS before it, you need to change your mind.

Git is a very agile and you can use different workflows with it. Cloning repositories is more needed for a team work, not for local development (IMHO).

Branches is a good alternative for you.

See. Let's set master branch of your repository for a production-ready code. Let's create another branch for development:

$ git checkout -b development master

Now you are working on the development branch.

You could use different branches for each feature you want to develop. It's very easy and helpful.

Let's imagine you want to implement some new feature, you need to create a new branch:

$ git checkout -b newfeature development

Now you can work with your code, add files, commit and so on.

Next you need to merge your new developed feature to the development branch:

$ git add .
$ git commit -m "My last changes for the new feature"
$ git checkout development
$ git merge newfeature

Now your new code from the newfeature branch merged into the development branch.

For sometime in the future when you decide that your code in the development branch get some milestone, you could merge all the changes from development to master branch.

It's a very basic workflow, it can be helpful for the many branches.

My advise for you now: read more about git, branching, stashing (very-very-very helpful for quick fixes). And after some time you will get a great effort from using git.

Good luck.

这篇关于Git基本工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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