官术网_书友最值得收藏!

Pulling and stashing

That leaves us with the final part of the Git basics, pulling code from the server. Whenever your coworkers push code to the server, you want to get it from there on to your own computer. You can pull code using the git pull command. Just like when you push, a pull can result in a merge conflict. Whenever this happens, there are two things you can do. You can either commit your current work, pull the code from the server, and then resolve the conflicts. Or you can stash your changes, meaning you put them aside for the time being and reset all the files as they were when you last pulled, and then do the pull and apply your stash over the newly pulled code. A conflict between your current code and the stash will still occur, but you can now resolve it manually before committing your code.

 

Stashes are an easy way to put some code aside, either because you want to pull from the server or because you want to try some alternative solution to a problem without losing your current solution. It is good to notice here that new files in your repository will not be stashed; they will simply continue to exist in your current working directory. You can create a stash using the git stash command. You can optionally give your stash a name. You can then apply any stash you like or apply and delete your latest stash or any other stash by index. Try committing a file, then change and save its contents, and see what happens to it after each of the following commands:

git stash
git stash pop
git stash save "My awesome stash"
git list
git stash apply 0
git stash drop 0
If you apply a stash to your working directory and you get a merge conflict, theirs is actually your stash. I once lost quite a lot of work that way! Imagine this: you want to pull, but get a conflict. You stash, pull, and then apply the stash. Your stash feels like your code (or ours). However, when you pull their code, it actually becomes your code. Now when you apply the stash to your code, the stash is their code. It makes sense when you think about it, but usually a stash does not feel like  theirs. So remember, when you want to resolve and keep your stash, resolve using theirs.
主站蜘蛛池模板: 汝州市| 大化| 巴林左旗| 北宁市| 社会| 沅江市| 方正县| 镇巴县| 临沭县| 西宁市| 云霄县| 汉阴县| 任丘市| 长春市| 白玉县| 突泉县| 甘肃省| 沈阳市| 西宁市| 旬邑县| 太湖县| 筠连县| 安吉县| 浠水县| 建昌县| 太保市| 大宁县| 股票| 灵璧县| 辽宁省| 嘉义市| 宜兰县| 阿坝县| 昌邑市| 临清市| 富平县| 鄄城县| 上虞市| 蓝田县| 枣阳市| 金乡县|