Git使用

git分支

查看分支

git branch                        //查看本地分支
git branch -r                    //查看遠端分支
git branch -a                    //查看所有分支

創建分支

git branch    [branch name]        //創建本地分支

切換分支

git checkout [branch name]        //切換分支
git checkout -b [branch name]    //創建+切換分支,相當於git branch & git checkout

推送新分支

git push origin [branch name]

刪除分支

git branch -d [branch name]        //刪除本地分支
git push origin :[branch name]    //刪除遠端分支,分支前面的冒號代表刪除


git處理衝突

當拉取下來的文件與本地修改的文件有衝突,先提交你的改變,或者先將你的改變暫時存儲起來

1、將本地修改存儲起來

git stash

2、pull內容

 git pull 

3、還原暫存的內容

git stash pop stash@{0}

也可以簡寫

git stash pop

git放棄修改文件

本地修改了文件但還未add

git checkout --filename        //單個文件

git checkout .                //全部文件

本地新增了文件還未add

rm filename / rm dir -rf    //單個文件 //直接刪除文件


git clean -xdf                //全部文件

// 刪除新增文件,如果文件已經git add到緩存區,並不會刪除

已經git add提交到了暫存區

git reset HEAD filename     //單個文件
git reset HEAD .            //全部文件

git add以及git commit之後

git reset commit_id            //commit_id是你回到的那個節點,可通過git log查看,可以只選前幾位

//撤銷之後,已經commit的修改還在工作區

git reset --hard commit_id

//撤銷之後,已經commit的修改將會刪除,仍在工作區/暫存區的代碼不會清除

git另一個進程還在運行

問題描述

出現這種情況可能是git在執行的過程中,你中止之後異常,進程一直停留

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

問題原因

因爲進程的互斥,所以資源被上鎖,但是由於進程突然崩潰,所以未來得及解鎖,導致其他進程訪問不了。

問題解決

打開隱藏文件夾選項,進入工作區文件目錄的隱藏文件.git,把其中的index.lock問價刪除掉

git本地版本回退

  • 通過tortoiseGit查看日誌show log
  • 選中需要回退的代碼版本
  • 右鍵選擇Reset "master to this...
  • 在彈出的窗口Reset Type選擇Hard:Reset working tree and index(discard all local changes)

git lfs的使用

操作步驟:

1、安裝lfs

安裝包地址:https://git-lfs.github.com/

2、把項目從gitlab clone下來

F:\鏡像文件>git clone https://xxx/dc/vmware-image.git
Cloning into 'vmware-image'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

3、初始化git lfs項目

F:\鏡像文件\vmware-image>git lfs install
Updated git hooks.
Git LFS initialized.

4、選擇要作爲大文件處理的文件擴展名

F:\鏡像文件\vmware-image>git lfs track "*.wim"
Tracking "*.wim"

5、提交文件

F:\鏡像文件\vmware-image>git add install.wim
Possibly malformed conversion on Windows, see `git lfs help smudge` for more det
ails.

F:\鏡像文件\vmware-image>git commit -am "添加install.wim"
[master 43c28b8] 添加install.wim
 1 file changed, 3 insertions(+)
 create mode 100644 install.wim

F:\鏡像文件\vmware-image>git push origin xxx
Locking support detected on remote "origin". Consider enabling it with:
  $ git config lfs.https://xxxx/dc/vmware-image.git/info/lfs.loc
ksverify true
Uploading LFS objects: 100% (1/1), 11 GB | 23 MB/s, done
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 407 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for xxx, visit:
remote:   https://xxx/dc/vmware-image/merge_requests/new?merge_
request%5Bsource_branch%5D=xxx
remote:
To https://xxx/dc/vmware-image.git
 * [new branch]      xxx -> xxx



參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章