【问题标题】:git add --all in Git 2.3.5git add --all 在 Git 2.3.5
【发布时间】:2016-11-12 03:02:34
【问题描述】:

我正在尝试将现有项目上传到 Github。
我正在使用 Git 2.3.5,因为较新的版本与 Mac OS X Lion (10.7.5) 不兼容。
我尝试使用git add eu,因为我在指南中找到了。结果是以下错误:

fatal: pathspec 'eu' did not match any files

我也试过git add .git add --all。它给了我一个完全空白的新行。

那么,如何将我现有的 Maven 项目上传到 Github?

  • Mac OS X v10.7.5
  • Git V2.3.5

新错误:

MBA-10-09:~ myname$ git push -u origin master
To https://github.com/myname/importer.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/myname/importer.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

MBA-10-09:~ myname$ git config --global pull.rebase true
MBA-10-09:~ myname$ git stash
Saved working directory and index state WIP on master: b1c9c72 Added Importer v0.1-Beta
HEAD is now at b1c9c72 Added Importer v0.1-Beta
MBA-10-09:~ myname$ git pull --rebase
warning: no common commits
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
From https://github.com/bys1/importer
 * [new branch]      master     -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

MBA-10-09:~ myname$ git stash pop
Removing README.md
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .CFUserTextEncoding
    .bash_history
    .cache/
    .config/
    .cups/
    .dropbox/
    .eclipse/
    .gitconfig
    .gmwoommrc
    .local/
    .m2/
    .mediafire/
    .oracle_jre_usage/
    .p2/
    .sh_history
    .ssh/
    .tkyczxzn
    Applications/
    BuildData/
    BuildTools.log.txt
    Bukkit/
    CraftBukkit/
    Desktop/
    Documents/
    Downloads/
    Dropbox/
    Library/
    Movies/
    Music/
    Pictures/
    Public/
    Spigot/
    apache-maven-3.2.5/
    craftbukkit-1.10.jar
    magic.mgc
    spigot-1.10.jar
    work/


It took 2.42 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (3eb015298d6369d65ba7551f0f81178b63cc119e)

【问题讨论】:

  • Git 不关心(甚至不知道)Java 包或 Maven 工件 ID。你的目录结构是什么?您是添加新文件还是推送现有提交有问题?
  • 我正在尝试将我的项目上传到 Github,但是 git add --all 没有做任何事情。
  • 我是 Github 新手,但没想到会这样。
  • 但是你说你有一个“现有项目”。您是否已经有一个本地 Git 存储库来保存该项目? git add --all 只添加已经被跟踪的文件。
  • 我在 Eclipse 中有一个 Maven 项目。不知道我是否有任何本地存储库,我该如何找到?我是 Github 的菜鸟。

标签: macos github


【解决方案1】:

The article 确实提到:

在命令/终端上,导航到您之前克隆的本地 GitHub 存储库

这意味着您必须首先克隆一个 GitHub 存储库(并且在此之前首先:create a repo on GitHub

cd c:\users\mylogin
git clone https://github.com/<myaccount>/<my-test-repo>.git

您将在 c:\users\mylogin\ 中看到一个 .git 文件夹。

您可以在同一个仓库中添加文件,然后:

git add "name of generated folder" (in my case git add org) then enter
git commit -m "Sensible commit message"
git push -u origin master

如果您的 git 足够新(2.5+,请使用 2.9),请输入(仅一次)

 git config --global rebase.autosquash true
 git config --global pull.rebase true

这样,当您在git push 上出现“Updates were rejected because the remote contains work that you do not have locally”之类的错误时,您只需:

git pull

您的本地分支将基于其更新的远程跟踪分支 (origin/xxx)。
如果你有工作正在进行中(没有被跟踪,或者只是添加到索引中),它会被隐藏起来让你进行变基,然后弹出回你的工作树。

使用 git 2.3.5,git config --global pull.rebase true 将起作用。
剩下的就是:

git stash
git pull --rebase
git stash pop

【讨论】:

  • git 2.3.5 怎么样?
  • @Priv 如果可以的话,只需升级你的 git:stackoverflow.com/q/8957862/6309
  • 最新版本的git好像不兼容Mac OS X Lion。
  • @Priv Sure:git branch --set-upstream-to=origin/master master 后重试
  • 在 git stash 之后:fatal: git-write-tree: error building trees
猜你喜欢
  • 1970-01-01
  • 2016-02-14
  • 2014-05-25
  • 2015-03-16
  • 2013-07-17
  • 1970-01-01
  • 2014-11-20
  • 2018-07-09
相关资源
最近更新 更多