Node.js和VUE-CLI 3.0安裝


1、先安裝Node.js, 去官網下載https://nodejs.org/en/download/

2、安裝成功后,通過npm -v和node -v查看npm和node的版本。出現版本顯示即安裝成功。

3、通過npm質量安裝VUE-CLI,如果之前安裝過VUE-CLI,先通過npm uninsatll -g vue-cli指令卸載之前的安裝。然后在輸入npm install -g @vue/cli

4、通過vue -V查看安裝的vue版本,顯示則安裝成功。

5、在Git上建一個倉庫,只需要輸入項目名稱跟描述(其實也可以不填描述),記得,不要選上Initialize this repository with a README,很重要。

6、點擊create repository之后,就會看到這個提示頁面,重點來了。
這里其實就是說這個倉庫還是空的,你可以從這個倉庫克隆出新的倉庫,也可以把一個已有的本地倉庫與之關聯,然后,把本地倉庫的內容推送到GitHub上。這個時候你就可以在需要的文件夾目錄下創建 vue 項目了。

7、構建VUE項目,進入指定的文件夾,輸入vue create project_name創建一個項目名為project_name的項目

8、選擇手動配置項目創建項目

9、進入新建的的項目文件夾,輸入如下:

cd project_name
git init
// 添加所有項目文件
git add .
// 雙引號內的描述可以自己填寫其他內容
git commit -m “vue初始化項目”
// 將本地的項目與遠程倉庫關聯起來,remote-repository-address為遠程倉庫地址,可以去github去獲取,然后執行git remote -v查看是否關聯成功。根據自己項目倉庫路徑填寫origin后面的地址,
git remote add origin git@github.com:yourusername/yourdemoname.git
推送到遠程倉庫上
git push -u origin master

**********

當在執行git push -u origin master的時候可能會不成功,報如下錯誤

! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/#####/vue-project.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.

意思就是更新被拒絕提示你應該git pull一下,當執行git pull origin master時,報錯又來啦fatal: refusing to merge unrelated histories,

意思是拒絕合並不相關的歷史。查閱了下資料,可以在git pull命令后加上–allow-unrelated-histories選項,問題就迎刃而解了,
git pull origin master --allow-unrelated-histories
然后就可以愉快的git push origin master了,最后去github上刷新下看看是否有本地提交的項目。
*************

10、如果之前windows平台沒有安裝git,需要先安裝

10.1 進入下載官網-https://git-scm.com/download下載git安裝包,選擇適合操作系統的版本下載安裝,一路next下去,完成安裝。

10.2 安裝完成后,設置系統變量path,添加變量值C:/program Files/Git/cmd(注意此處的C/:program Files是你安裝Git的路徑)

10.3 驗證git是否安裝成功,在命令行下輸入git --version看看版本號。

10.4 git安裝完之后,就要配置可以操作遠程倉庫的密鑰。先注冊github賬號,此處不表。

10.5 git安裝好后,可以在項目路徑下點擊右鍵,選擇git bash here,進入命令行。

10.6 輸入ssh-keygen -t rsa -C "your_email@youremail.com"  這里的郵箱就是你創建github賬號的郵箱

10.7 輸入密碼確認后,將會在本地文件夾中創建密鑰文件。

會在 .ssh 目錄生產兩個文件:id_rsa和id_rsa.pub
用記事本打開.ssh目錄下的id_rsa.pub文件,復制里面的內容;

進入github個人設置頁面,選擇ssh keys后點擊new ssh key.

把拷貝的密鑰粘貼在新建的ssh key下即可。

10.8 測試ssh連接github 輸入ssh -T git@github.com

 

附一些git常用操作

***********************

1、克隆一個項目下來
git clone giturl/倉庫名.git
cd autotest001
vim help.txt
git init
git add help.txt
git commit -m "first commit"
git remote add origin https://github.com/aaron221/autotest001.git
假如執行完上一句命令后,出現了fatal: remote origin already exists.
則執行一下這個命令 git remote rm origin然后再重新執行上一句命令
git push -u origin master

2、上面是一開始的操作,后面的上傳文件操作可以簡化為

git add anotherfile.txt
git commit -m "這是第二次上傳文件了"
git push


3、.拉取git上的文件
git pull

4、創建本地分支
git checkout -b 分支名
git add filename
git commit -m "這是提交的分支信息"
git push

5.刪除本地分支
git checkout master
git branch -d 分支名
git branch -r -d origin/firstbranch 刪除遠程分支
git push origin :分支名

6.分支合並到主支上去
git checkout master
git merge firstbranch

7.解決分支合並沖突
$ git merge firstbranch
提示如下:
Auto-merging firsthelp.txt
CONFLICT (content): Merge conflict in firsthelp.txt
Automatic merge failed; fix conflicts and then commit the result.

$ cat firsthelp.txt
help to you...\
這是需要合並的內容
<<<<<<< HEAD
這是master上的內容
=======
這是firstbranch上的neir

>>>>>>> firstbranch
解決沖突修改后
help to you...\
這是需要合並的內容
這是master上的內容這是firstbranch上的neir

git add filename
git commit -m "解決沖突"
git push


8、項目版本操作
git reset --hard HEAD^ 返回上一個版本
git reflog 查看版本號xinx
git reset --hard 版本號 回到指定版本

9、對需要刪除的文件、文件夾進行如下操作:

git rm test.txt (刪除文件)

git rm -r test (刪除文件夾)

10、提交修改

git commit -m “Delete some files.”

 


config1:git push的時候跳過輸入用戶名和密碼
1通過創建文件存儲用戶名和密碼
打開$HOME$目錄,如果你不知道在哪,那么可以使用git bash 輸入echo $HOME查看這個路徑,一般都在C:\Users\administrator下面,注意cmd下面這個命令是查看不到的。然后使用命令創建一個文件名為.git-credentials,在Windows中是不允許直接創建“.”開頭的文件。輸入以下命令:
touch .git-credentials

vim .git-credentials

https://{username}:{password}@github.com

第一句是創建文件,第二句使用vim打開文件進行編輯,輸入第三行的內容,用戶名和密碼是你自己的,保存退出。
接下來輸入下面的命令:

git config --global credential.helper store

這個添加git config的內容,執行完畢之后再$HOME目錄下的.gitconfig文件中會多了一項:

[credential]

helper = store


這時候重新開啟git bash進行git push的時候就不用輸入用戶名和密碼了,並且如果你注釋了上面這句,那么git push就會重新讓你輸入用戶名和密碼進行驗證。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM