最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】如何把git中的本地的改动(local changes)上传(upload/commit/push)到git服务器的仓库中

Git crifan 6152浏览 0评论

【问题】

折腾:

【记录】再次尝试用git上传BlogsToWordpress的代码到SourceForge中git仓库

期间,无意间,多上传了一个文件到git服务器。

所以此处是:

先本地删除了该文件。

即对于本地的git,做了一定改动和更新。

想要把这个更新,即删除了某个文件的改动,上传到git服务器中去。

【折腾过程】

1. 此处,手动rm删除文件,肯定是不可以的。

所以需要通过git去

git rm

一个文件,然后再push,貌似执行成功了:

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ rm
.git/                                        libs/                                        modifiedPostPattern_Netease_againinput4.txt
BlogsToWordpress.py                          materials/                                   modifiedPostPattern_againinput4.txt
cmd_example.txt                              modifiedPostPattern_Baidu_serial_story.txt

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ rm cmd_example.txt

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ cp ../BlogsToWordpress
BlogsToWordpress/                                   BlogsToWordpress_2013-08-26_home_fixbugDiandian.7z
BlogsToWordpress_2013-08-26_home_fixbugDiandian/

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ cp ../BlogsToWordpress_2013-08-26_home_fixbugDiandian/BlogsToWordpress/cmd_example.txt .

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ ls
BlogsToWordpress.py  libs       modifiedPostPattern_Baidu_serial_story.txt   modifiedPostPattern_againinput4.txt
cmd_example.txt      materials  modifiedPostPattern_Netease_againinput4.txt

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git rm cmd_example.txt
rm 'cmd_example.txt'

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git push originhttps master
Password for 'https://[email protected]':
Everything up-to-date

即,出现了

Everything up-to-date

貌似没有更新上去。

2.然后去SourceForge服务器上确认一下,更新是否成功上传到服务器了。

结果是,删除文件的改动,没有传上去:

rm file not update to git_thumb

3.此问题,和这个:

git push says everything up-to-date even though I have local changes

很类似。

然后去试了半天:

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git ls-remote originhttps
Password for 'https://[email protected]':
b537fedb56dee940ea99054dbcf8ff95a4305ed3        HEAD
b537fedb56dee940ea99054dbcf8ff95a4305ed3        refs/heads/master

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git ls-remote .
b537fedb56dee940ea99054dbcf8ff95a4305ed3        HEAD
b537fedb56dee940ea99054dbcf8ff95a4305ed3        refs/heads/master
b537fedb56dee940ea99054dbcf8ff95a4305ed3        refs/remotes/originhttps/master

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git log -1
commit b537fedb56dee940ea99054dbcf8ff95a4305ed3
Author: U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>
Date:   Tue Aug 27 23:20:50 2013 +0800

    first add all blogstowordpress v17.7 files into git

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git checkout master
D       cmd_example.txt
Already on 'master'

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git log -g -2 HEAD
commit b537fedb56dee940ea99054dbcf8ff95a4305ed3
Reflog: HEAD@{0} (U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>)
Reflog message: checkout: moving from master to master
Author: U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>
Date:   Tue Aug 27 23:20:50 2013 +0800

    first add all blogstowordpress v17.7 files into git

commit b537fedb56dee940ea99054dbcf8ff95a4305ed3
Reflog: HEAD@{1} (U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>)
Reflog message: commit (initial): first add all blogstowordpress v17.7 files into git
Author: U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>
Date:   Tue Aug 27 23:20:50 2013 +0800

    first add all blogstowordpress v17.7 files into git

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$

还是一头雾水。

4. 再去参考:

How to push local changes to a remote git repository on bitbucket

去试试-all:

结果都不行:

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git push originhttps master -all
error: unknown switch `a'
usage: git push [<options>] [<repository> [<refspec>...]]

    -v, --verbose         be more verbose
    -q, --quiet           be more quiet
    --repo <repository>   repository
    --all                 push all refs
    --mirror              mirror all refs
    --delete              delete refs
    --tags                push tags (can't be used with --all or --mirror)
    -n, --dry-run         dry run
    --porcelain           machine-readable output
    -f, --force           force updates
    --recurse-submodules[=<check>]
                          controls recursive pushing of submodules
    --thin                use thin pack
    --receive-pack <receive-pack>
                          receive pack program
    --exec <receive-pack>
                          receive pack program
    -u, --set-upstream    set upstream for git pull/status
    --progress            force progress reporting


Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git push originhttps master:master
Password for 'https://[email protected]':
Everything up-to-date

5.参考:

How can I upload committed changes to my GitHub repository?

再去试试:

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git commit -a
error: cannot run vi: No such file or directory
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git commit
error: cannot run vi: No such file or directory
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git commit -a -m "delete cmd_example.txt"
[master 2905c78] delete cmd_example.txt
 Committer: U-NYBDHB7EB3XEHP6\Administrator <Administrator@PC-20130611GART.(none)>
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:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

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

    git commit --amend --reset-author

 1 files changed, 0 insertions(+), 1287 deletions(-)
 delete mode 100755 cmd_example.txt

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$ git push originhttps master
Password for 'https://[email protected]':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 269 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: <Repository /git/p/blogstowordpress/code.git> refresh queued.
To https://[email protected]/p/blogstowordpress/code
   b537fed..2905c78  master -> master

Administrator@PC-20130611GART /cygdrive/e/Dev_Root/SourceForge/git/BlogsToWordpress
$

貌似是可以,再去服务器上确认一把:

not that deleted cmd_example.txt file now_thumb

说明的确是可以了。

 

【总结】

所以,总结出来的逻辑是:

1.当git中,有任何本地更新时

要注意的是:

需要通过git去操作才可以。

比如删除文件,不能直接用rm,而需要用到git rm等等。

2.然后对于git本地的更新,想要上传到git服务器中:

(1)先要把更新,commit到本地的git仓库中:

git commit -a -m "your update message"

(2)再把本地的(增加了更新的)git仓库的内容push到服务器上:

git push originhttps master

其中:

  • originhttps:是我之前为https建立的一个remote的名字,其他一般人都是origin

    转载请注明:在路上 » 【已解决】如何把git中的本地的改动(local changes)上传(upload/commit/push)到git服务器的仓库中

    发表我的评论
    取消评论

    表情

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址
    83 queries in 0.177 seconds, using 22.08MB memory