git常用命令
提交代码入口唯一,保证避免出现文件被覆盖情况。
1.新建项目
echo "# fast_ring_queue" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/dodng/fast_ring_queue.git
git push -u origin master
2.新增代码
注意:空文件夹不能用这种方式,可以创建一个空的文件。
git add README.md
git commit -m "first commit"
git push -u origin master
3.修改代码
git commit main.c -m "add author"
git push -u origin master
问题:error: failed to push some refs
解决A:
强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f[小心覆盖已修改的文件]
现象:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/dodng/comse.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决B:
git pull --rebase origin master
git push -u origin master
2. 先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
4.拉代码
git clone https://github.com/dodng/grumpy grumpy
5.删除代码
rm test.txt
git status
git rm test.txt (递归删除文件夹 -rf)
git commit -m "first commit"
git push -u origin master
6.恢复部分代码文件
git fetch
git checkout origin/master -- Makefile

浙公网安备 33010602011771号