I
I
IvankoPo2017-08-20 16:44:48
git
IvankoPo, 2017-08-20 16:44:48

Git not pushing changes?

I am learning git. I decided to upload two files to the repository, initialized the directory and made

git add client.py server.py 
git commit -m "echo server, firts commit"
git push -u origin master

"working directory looks like this
...................socket_berkley
................... / .... ................\
...............server.py.............client. py
"
everything is fine, everything started running further in the working directory, I decided to create the socket directory and the echo-server directory in it
and copy those two files there
mkdir socket
mkdir echo-server
cp client.py server.py socket/echo-server/

then pushed the matter again
MacBook-Pro-ivan:socket_berkley ivan$ git add socket/
MacBook-Pro-ivan:socket_berkley ivan$ git commit -m "add directory socket"

"became
.............socket_berkley
.........................|
....... ................socket
........................|
...... .............echo-server
.............. /............\
.............client.py........server.py
"
git log looked like this
MacBook-Pro-ivan:socket_berkley ivan$ git log
commit a0f25758147eb11e6439a607ed0f010b8037a8f7
Author: IvankoPo <[email protected]>
Date:   Sun Aug 20 15:29:38 2017 +0300

    add directory socket

commit 5fea3bb214b26d0170d0bbd70ca902460fecd45d
Author: IvankoPo <[email protected]>
Date:   Sun Aug 20 15:17:22 2017 +0300

    echo server, firts commit

then I decided to roll back the changes, that is, those 2 directories
git checkout 5fea3bb
on the local computer are deleted again
"
....................socket_berkley
............ ....... / ....... \
.............server.py... ..........client.py
"
and on github
"
.............socket_berkley
.................. ........|
.......................socket
................. .........|
...................echo-server
.................. /............ \
.............client.py........server.py
"
so I decided to push the changes to github, that is, return it to the first state By running
the command
git add  # я понял что лоханулся надо было git add socket
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
git commit -m "back to the first"
HEAD detached at 5fea3bb
Untracked files:
  .idea/

nothing added to commit but untracked files present
MacBook-Pro-ivan:socket_berkley ivan$ git push -u origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date

realized that mistake
git add client.py server.py 
MacBook-Pro-ivan:socket_berkley ivan$ git commit -m "back to the first state"
HEAD detached at 5fea3bb
Untracked files:
  .idea/

nothing added to commit but untracked files present

and then errors started, then I wanted to return to the second state
"
.............socket_berkley
........................ ..|
......................socket
....................... ...|
...................echo-server
...... /..... ......... \
.............client.py........server.py
"
MacBook-Pro-ivan:socket_berkley ivan$ git checkout master
error: The following untracked working tree files would be overwritten by checkout:
  .idea/vcs.xml
Please move or remove them before you can switch branches.
Aborting
MacBook-Pro-ivan:socket_berkley ivan$ git checkout a0f2575
error: The following untracked working tree files would be overwritten by checkout:
  .idea/vcs.xml
Please move or remove them before you can switch branches.
Aborting

the log shows that one commit disappeared to which I wanted to return
MacBook-Pro-ivan:socket_berkley ivan$ git log
commit 5fea3bb214b26d0170d0bbd70ca902460fecd45d
Author: IvankoPo <[email protected]>
Date:   Sun Aug 20 15:17:22 2017 +0300

    echo server, firts commit

decided to manually restore those directories again
MacBook-Pro-ivan:socket_berkley ivan$ ls
client.py	server.py
MacBook-Pro-ivan:socket_berkley ivan$ mkdir socket
MacBook-Pro-ivan:socket_berkley ivan$ cd socket/
MacBook-Pro-ivan:socket ivan$ mkdir echo-server
MacBook-Pro-ivan:socket ivan$ cd ../
MacBook-Pro-ivan:socket_berkley ivan$ ls
client.py	server.py	socket
MacBook-Pro-ivan:socket_berkley ivan$ cd client.py server.py socket/echo-server/
-bash: cd: client.py: Not a directory
MacBook-Pro-ivan:socket_berkley ivan$ cp client.py server.py socket/echo-server/
MacBook-Pro-ivan:socket_berkley ivan$ git status
HEAD detached at 5fea3bb
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

  new file:   .idea/vcs.xml
  deleted:    client.py
  deleted:    server.py

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

  .idea/inspectionProfiles/
  .idea/misc.xml
  .idea/modules.xml
  .idea/socket_berkley.iml
  .idea/workspace.xml
  socket/

and push again
MacBook-Pro-ivan:socket_berkley ivan$ git add socket
MacBook-Pro-ivan:socket_berkley ivan$ git commit -m "add directory socket"
[detached HEAD 1cdab81] add directory socket
 3 files changed, 6 insertions(+)
 create mode 100644 .idea/vcs.xml
 rename client.py => socket/echo-server/client.py (100%)
 rename server.py => socket/echo-server/server.py (100%)
MacBook-Pro-ivan:socket_berkley ivan$ ls
socket
MacBook-Pro-ivan:socket_berkley ivan$ git push -u origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date

for some reason it didn't work
git log && git status
MacBook-Pro-ivan:socket_berkley ivan$ git log
commit 1cdab81099a4f10650e10566b7816a1262397886
Author: IvankoPo <[email protected]>
Date:   Sun Aug 20 15:51:31 2017 +0300

    add directory socket

commit 5fea3bb214b26d0170d0bbd70ca902460fecd45d
Author: IvankoPo <[email protected]>
Date:   Sun Aug 20 15:17:22 2017 +0300

    echo server, firts commit
MacBook-Pro-ivan:socket_berkley ivan$ git status
HEAD detached from 5fea3bb
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)

  modified:   socket/echo-server/client.py
  modified:   socket/echo-server/server.py

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

  .idea/inspectionProfiles/
  .idea/misc.xml
  .idea/modules.xml
  .idea/socket_berkley.iml
  .idea/workspace.xml

no changes added to commit (use "git add" and/or "git commit -a")

decided to add comments to the code and again add && commit
MacBook-Pro-ivan:socket_berkley ivan$ git add socket
MacBook-Pro-ivan:socket_berkley ivan$ git commit -m "add coments"
[detached HEAD 594bcb6] add coments
 2 files changed, 25 insertions(+), 25 deletions(-)
 rewrite socket/echo-server/client.py (87%)
 rewrite socket/echo-server/server.py (77%)

git status shows this, for me, so something is wrong
MacBook-Pro-ivan:socket_berkley ivan$ git status
HEAD detached from 5fea3bb
Untracked files:
  (use "git add <file>..." to include in what will be committed)

  .idea/inspectionProfiles/
  .idea/misc.xml
  .idea/modules.xml
  .idea/socket_berkley.iml
  .idea/workspace.xml

nothing added to commit but untracked files present (use "git add" to track)

I try to push not to push
MacBook-Pro-ivan:socket_berkley ivan$ git push -u origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date

What is the problem and how to fix it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wexter, 2017-08-20
@IvankoPo

after rolling back to the previous revision, you changed the tree locally, it remained old on the server. to change the tree on the server it was necessary to do

git push --force
, then the tree on the server will be overwritten and will be the same as the local one

C
Cat Anton, 2017-08-20
@27cm

The main problem is that you started changing the history of commits after you pushed them. Of course, if you are the only developer in the project or this is your personal feature branch that no one rules except you, then it will do. But if you do this with project branches that other developers are working on, then you will get a lot of problems.
Read more:
https://git-scm.com/book/en/v1/%D0%92%D0%B5%D1%82%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question