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

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.
主站蜘蛛池模板: 晋城| 丹江口市| 酒泉市| 靖西县| 裕民县| 武乡县| 富源县| 碌曲县| 樟树市| 宁德市| 鞍山市| 安阳市| 怀化市| 招远市| 南漳县| 赤壁市| 江安县| 灌阳县| 桐庐县| 治县。| 高碑店市| 河间市| 汉川市| 博罗县| 肥城市| 饶平县| 天门市| 始兴县| 镇康县| 栾川县| 泰和县| 乡城县| 高雄市| 绍兴县| 邻水| 吉隆县| 济南市| 德江县| 商都县| 龙江县| 通榆县|