iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 17
0
自我挑戰組

Experience of a backend novice系列 第 17

如何移除未在追蹤清單內的檔案呢? 試試看 'git clean'

Day seventeen

How could I remove untracked file? Let's do 'git clean'
如何移除未在追蹤清單內的檔案呢? 試試看 'git clean'

In the previous article, we introduced 'git reset', how to delete files from tacking list, or make them untracked.
上一篇文章我們介紹了如何使用'git reset' 來將追蹤清單內的檔案移除,或者變成未追蹤。

What if we add a few files and hasn't added them into tracking list? What should we do to remove th
那如果我們新增了幾個檔案,但尚未將之加入追蹤清單內,那我們該怎麼移除他們呢?

Cliche! Action is louder than speaking.
老話一句,坐而言不如起而行!

If you have followed each step from the beginning of this series of article, your log should looke like the image below.
如果你從一開始就照著這系列文章的進度走,你的log應該會如下圖:

Now let's add a few new files:
現在讓我們新增幾個檔案:

touch example 4.html
touch example 5.html
git status

As follows, there are two untracked files in our working directory.
如下,我們現在有兩個未在追蹤清單內的檔案

So how could we remove them?
現在該怎麼把他們移除呢?

Enter:
輸入:

git clean -f

As image above, we've removed both of them.
如上圖,這樣我們就把兩個檔案都移除了。

Some people might ask, what if I just want to remove one of them?
那有人會問,如果我只打算要移除其中一個檔案呢?

Let's go one step backward:
讓我們回到上一步:

touch example4.html
touch example5.html
git status

Okay now we are at where we were. How should we do to only remove example4.html?
好現在我們回到上一步了。現在我們只想要移除'example4.html',那該怎麼做呢?

Enter:
輸入:

git clean -i

As image above, enter 3 'select by numbers'
如上圖,現在我們輸入3 'select by numbers'

And then enter 1, and press enter again.
接著輸入1然後再按一次enter

And then enter 1 'clean'
然後輸入 1 'clean'

Well done! We've successfully deleted example4.html, and keep example5.t
好啦,現在我們成功地刪除了example4.html,但保留了example5.html.

Some people might ask, can I just delete them manually?
也許有人會說,那我手動刪除行嗎?

Of course you can. However, why git is so powerful is the ability to eradicate the potential of humor mistake. So it's better to use Git!
當然可以,但是使用git的宗旨就在於最大的去除人為失誤的可能性,所以還是建議使用git哦!


上一篇
哎呀,不小心加錯檔案到追蹤清單了。別擔心,使出'git reset'!
下一篇
git branch,想怎麼開發就怎麼開發
系列文
Experience of a backend novice30

尚未有邦友留言

立即登入留言