简体   繁体   中英

Git, Initial commit with changes

In the server...

$ git --version
git version 1.8.3.1

In the client

λ git --version
git version 2.17.1.windows.2

I have a git folder (in windows) with new files that are just going to go up

I initiallized my folder

C:\Users\IT.Developer\MigrationProject
λ git init
Initialized empty Git repository in C:/Users/IT.Developer/MigrationProject/.git/

C:\Users\IT.Developer\MigrationProject (master -> origin)
λ ls -al
total 21
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:58 ./
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:57 ../
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:58 .git/
-rw-r--r-- 1 IT.Developer 1049089 7 Sep 13 08:58 NewFile2BeCommitted.txt

> Blockquote

C:\Users\IT.Developer\MigrationProject (master -> origin)

I added the File (Only one for porpouse examples)!

λ git add .

C:\Users\IT.Developer\MigrationProject (master -> origin)
λ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   NewFile2BeCommitted.txt


C:\Users\IT.Developer\MigrationProject (master -> origin)

Now I do it the commit....

λ git commit -m "Upload 2, test"
[master (root-commit) cf6cb7f] Upload 2, test
 Committer: Developer (Vertical Health Internal) <IT.Developer@INTERNAL.NET>
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. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 NewFile2BeCommitted.txt

C:\Users\IT.Developer\MigrationProject (master -> origin)

My next step was add to remote server...

λ git remote add origin git@192.168.5.200:/srv/git/project.git

C:\Users\IT.Developer\MigrationProject (master -> origin)

Here my pain...

λ git push origin master
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
To 192.168.5.200:/srv/git/project.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@192.168.5.200:/srv/git/project.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.

C:\Users\IT.Developer\MigrationProject (master -> origin)

I was trying to solve (jump) inconsistencies

λ git stash
No local changes to save

C:\Users\IT.Developer\MigrationProject (master -> origin)

I was trying to pull

λ git pull
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From 192.168.5.200:/srv/git/project
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
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


C:\Users\IT.Developer\MigrationProject (master -> origin)

Again, I was trying pull

λ git pull origin master
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
From 192.168.5.200:/srv/git/project
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

C:\Users\IT.Developer\MigrationProject (master -> origin)

But, again I can't

How solve this?

Looks like you started the project offline, without cloning the repo. And the first error seems to be because the remote repo already has commits in the branch you are trying to push.

Either start by cloning the repo first and then adding your commits or you could merge two unrelated branches that have separate history by passing the --allow-unrelated-histories option.

 git pull origin <branch name> --allow-unrelated-histories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM