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

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.
主站蜘蛛池模板: 社旗县| 分宜县| 兴国县| 容城县| 波密县| 安陆市| 左贡县| 浙江省| 南部县| 灌南县| 宿松县| 岳西县| 石楼县| 公主岭市| 木兰县| 保定市| 昌平区| 尚志市| 延边| 万荣县| 武城县| 开化县| 黄梅县| 浏阳市| 阳原县| 玛沁县| 永登县| 光山县| 德庆县| 东丰县| 肃南| 营山县| SHOW| 葵青区| 高要市| 罗城| 仪陇县| 蛟河市| 武胜县| 陈巴尔虎旗| 普兰县|