【问题标题】:How to push my changes back to the source code in git如何将我的更改推送回 git 中的源代码
【发布时间】:2011-08-12 06:08:10
【问题描述】:

我在 github 中创建了一个项目,然后对该项目进行了 git clone 以将所有源代码获取到我的机器上。

我对源代码做了一些修改,我的问题是:-

  1. 如何将我的更改提交到本地 git 存储库以及我在 github 中的分叉存储库?
  2. 原始源代码的作者将如何从 github 的分叉存储库中提取我的更改

【问题讨论】:

    标签: git github git-push


    【解决方案1】:
    1. 如何将我的更改提交到本地 git 存储库以及我在 github 中的分叉存储库?

    要为提交添加文件更改,请使用以下命令。

    git add .
    

    然后,通过

    进行本地提交
    git commit
    

    完成本地提交后,您可以将其推送到远程 GitHub 分支。

    git push
    
    1. 原始源代码的作者将如何从 github 的分叉存储库中提取我的更改

    要使您的源代码被原始 fork 拉取,您必须向项目所有者发送 拉取请求

    1. 转到您在 GitHub 上的分叉项目的网页。
    2. 点击页面右上角的拉取请求按钮
    3. 通过更改提交按钮选择您要提交的提交。
    4. 写一些关于您的更改、cmets 等的描述。
    5. 发送拉取请求并等待所有者回复。

    【讨论】:

    • 我在 git add 操作中错误地添加了某些不需要的文件,我如何回复说我不想添加一些文件
    • 使用“git reset HEAD ...”从提交中删除文件。
    【解决方案2】:

    检查一下
    Using GIT, how can I selectively pull / merge changes from another's 'fork'?
    How to commit my changes to the local git repository
    git commit -m "Your Message"

    How to commit my changes in forked repository in github? http://www.backdrifter.com/2011/02/09/working-on-forked-projects-using-github/
    http://help.github.com/fork-a-repo/

    How will the author of the original source code, pull my changes from the forked repository in github
    How do I show the changes which have been staged?
    http://www.kernel.org/pub/software/scm/git/docs/git-pull.html
    http://www.kernel.org/pub/software/scm/git/docs/everyday.html

    【讨论】:

      【解决方案3】:
      • 这是简单的方法:
        1. git 添加。
        2. git commit -m "最终改动"
        3. git remote add origin url(在url中添加你的仓库地址)
        4. git 远程 -v
        5. git push -f
        6. git push origin master

      【讨论】:

        【解决方案4】:
            follow these steps:
            git init (To initialize the repository as git)
            git add .( To add the changes to staging area)
            git commit -m "this is my first commit" ( Initialize it as a commit with the message)
            git add remote origin url (in url add the address of your repository)
        git pull origin master(to pull all the commits first otherwise they would be overridden)
            git -f push origin master(force push the chances to remote in the branch named master)
        

        【讨论】:

          【解决方案5】:

          我正在使用已部署的密钥 (ssh) 与带有用户/密码的 http (Repo -> Settings -> Deploy Keys)

          因此,在我 git clone 我的仓库之后,我不得不手动更改(或使用 git remote 添加新的)以下内容 来自:

          [remote "origin"]
              url = https://github.com/USERNAME/REPOSITORY.git
              fetch = +refs/heads/*:refs/remotes/origin/*
          

          收件人:

          [remote "origin"]
              url = git@github.com:USERNAME/REPOSITORY.git
              fetch = +refs/heads/*:refs/remotes/origin/*
          

          然后我确保在ssh-add -l(代理)中找到了我的密钥,然后我只是 git push

          【讨论】:

            猜你喜欢
            • 2023-03-09
            • 2018-06-24
            • 2019-09-18
            • 2019-04-23
            • 2012-04-22
            • 2016-01-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多