代码之家  ›  专栏  ›  技术社区  ›  smeeb

Git推送未看到我的所有更改

  •  0
  • smeeb  · 技术社区  · 10 年前

    我创建了一个私有GitHub回购,比如 https://github.com/myuser/myprivrepo ,并选择让它生成 .gitignore README.md 然后我在本地克隆了这个repo并添加了一堆文件。我还修改了 .git忽略 以及 阅读.md GitHub为我生成的。

    然后我这样做了:

    git commit -a -m "Initial commit with basic project structure."
    

    然后这个:

    git push
    

    它要求我进行认证,我做到了,“推送”似乎成功了。所以我回到GitHub仓库,在刷新页面后,我仍然只看到两个GitHub生成的文件( .git忽略 阅读.md ),但是,它们已经用我的更改进行了更新,甚至显示了正确更新的时间戳和提交消息(“ 初步提交基本项目结构。 ”)。

    因此,这就像推送对两个GitHub生成的文件进行了更改,但忽略了我的其他所有更改。这是我的 .git忽略 :

    *.class
    .mtj.tmp/
    *.jar
    *.war
    *.ear
    hs_err_pid*
    .metadata
    .gradle/
    bin/
    tmp/
    *.tmp
    *.bak
    *.swp
    *~.nib
    local.properties
    .settings/
    .loadpath
    .project
    .externalToolBuilders/
    *.launch
    .cproject
    .classpath
    .buildpath
    .target
    .texlipse
    

    我添加了一个文件,但GitHub上没有该文件的示例是 build.gradle ,这不应该与忽略文件中的任何内容匹配。思想?

    笔记 :当我右键单击本地repo根目录并转到 Git Gui 我看到GitHub上丢失的所有文件都在本地显示为“Unstaged”。不确定这是否意味着什么。

    2 回复  |  直到 10 年前
        1
  •  1
  •   Community CDub    4 年前

    git commit -a 不添加以前未跟踪的文件。您可以使用 git add . 在提交之前添加所有内容。这个 -a 现在不再需要了。

    Quoting the commit manual (强调矿井):

    -一个
    --全部

    告诉命令自动暂存已修改和删除的文件, 但是你没有告诉Git的新文件不会受到影响 .

        2
  •  1
  •   matsjoyce    10 年前

    看来GitHub不错。当你做 git commit -a ,git已经跟踪的所有文件都已提交,在您的情况下,这些文件将只是GitHub生成的文件。除非您 git add <file> git commit <file> 。若要检查git正在跟踪的文件,请使用 git ls-tree -r master --name-only 。做一个 git status 提交前:

    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            ### Files which will be committed with git commit -a appear here
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            ### Files which will NOT be committed with git commit -a appear here
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    要解决当前问题,您可以执行以下操作:

    $ # uncommit last commit
    $ git reset HEAD~1 --soft
    $ # add missing file
    $ git add build.gradle
    $ # recommit
    $ git commit -a -m "Initial commit with basic project structure."
    $ # force the push, as git will complain about overwriting a commit
    $ git push --force