Notes:XXX is username of local machine
➜ gittest git init
Initialized empty Git repository in /Users/XXX/Desktop/gittest/.git/
➜ gittest git:(master) echo "hello" > 1.md
➜ gittest git:(master) ✗ git add 1.md
➜ gittest git:(master) ✗ git commit -m"hello"
[master (root-commit) ea37549] hello
1 file changed, 1 insertion(+)
create mode 100644 1.md
gittest git:(master) ✗ git push --set-upstream /Users/XXX/Desktop/gittest/.git/ master
Branch 'master' set up to track remote branch 'master' from '/Users/XXX/Desktop/gittest/.git/'.
Everything up-to-date
gittest git:(master) ✗ echo "hello 2" >>1.md # change files
➜ gittest git:(master) ✗ git add 1.md
➜ gittest git:(master) ✗ git commit -m"hello 2"
[master 4593958] hello2
1 file changed, 1 insertion(+)
➜ gittest git:(master) ✗ git push
Everything up-to-date
➜ gittest git:(master) git pull
From /Users/XXX/Desktop/gittest/
* branch master -> FETCH_HEAD
Already up to date.
But it could not return file that was first commited to git push.
You have got a lot of things mixed up
git init
creates a full repository, therefore git commit
is the command to create a revision in that repository.
git push
is used to send changes to other repositories. You actually just created a self-reference to the same repository with your push. Therefore, everything is up-to-date, because you are trying to update the repository itself.
git pull
is used to get changes from other repositories and is by default a shortcut for git fetch
(update the local knowledge about remote repository) and git merge
to merge try to merge a current branch with the updated local knowledge of the branch in remote repository.
If you do not want to deal with remote repositories, do not use git pull
and git push
.
Moving around Git
To move to a specific commit in the repository, use git checkout
. But beware, git checkout <commit id>
will end up in detached HEAD state.
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.