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

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.
主站蜘蛛池模板: 江西省| 锦屏县| 什邡市| 巨野县| 高雄市| 五常市| 南皮县| 肇东市| 弋阳县| 昌宁县| 衡阳市| 阳城县| 安泽县| 棋牌| 井研县| 东城区| 余庆县| 普陀区| 赤壁市| 志丹县| 延边| 浮山县| 青冈县| 仪陇县| 漯河市| 巴南区| 定日县| 绵竹市| 兴义市| 浦东新区| 云龙县| 长武县| 渝北区| 呼伦贝尔市| 北海市| 卢湾区| 夏津县| 星座| 商河县| 吴旗县| 当雄县|