71. git github


HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id。

穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本
要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。

1.使用git log查看提交的历史提交记录

2.

71. git github

3.

.71. git github

4

    要关联一个远程库,使用命令git remote add origin [email protected]:path/repo-name.git;

关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;



linux  

检出项目与第一次提交:Geek [email protected] MINGW64 ~/Desktop
$ mkdir test


Geek [email protected] MINGW64 ~/Desktop
$ cd test


Geek [email protected] MINGW64 ~/Desktop/test

$ git clone https://github.com/forward66/life-is-wonderful.git


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$  git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working tree clean

Geek [email protected] MINGW64 ~/Desktop/test
$  ls
life-is-wonderful/


Geek [email protected] MINGW64 ~/Desktop/test
$ cd life-is-wonderful/


Geek [email protected]ESKTOP-Q4LA5N5 MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ ls
README.md


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ vi README.md


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$   vi 日记


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$  git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)


        "\346\227\245\350\256\260"


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


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ git add 日记
warning: LF will be replaced by CRLF in 日记.

The file will have its original line endings in your working directory.


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ git status


On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        new file:   "\346\227\245\350\256\260"



Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ git commit(上交到本地服务器)
[master 1fcb674] 我新加了一个日记文件
 1 file changed, 1 insertion(+)
 create mode 100644 "\346\227\245\350\256\260"


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ git status 
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$ git push(把本地的上传至网上)
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': forward66
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 353 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/forward66/life-is-wonderful.git
   6098fc1..1fcb674  master -> master


Geek [email protected] MINGW64 ~/Desktop/test/life-is-wonderful (master)
$  git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working tree clean


冲突用git pull

回到过去用git log

71. git github

71. git github

假如现在是2.0版本代码,想回到1.2版本,使用git log查看1.2版本的commitID 然后用 git reset --hard commitID 回到1.2这个版本,回到1.2版本以后,又想回到2.0版本怎么办,那就用git reflog 查看2.0版本的commitID 然后用git reset --hard commitID 回到2.0版本。

分支合并:如果你昨天发布了一个1.0版本,但是这个版本有BUG,那你不能用现在的分支,继续去完成软件开发,因为现在的分支很不安全,解决的办法是 新建一个 1.0版本的分支,并且修复BUG,然后把这个新建的分支merge到先前的那个分支。

相关文章:

  • 2021-08-26
  • 2021-11-14
  • 2021-05-19
  • 2021-06-09
  • 2021-05-28
猜你喜欢
  • 2021-04-07
  • 2022-12-23
  • 2021-11-23
  • 2021-08-28
  • 2021-06-17
  • 2021-12-31
  • 2021-09-16
相关资源
相似解决方案