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

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.
主站蜘蛛池模板: 屯昌县| 梓潼县| 维西| 若羌县| 胶南市| 比如县| 教育| 乳山市| 镇巴县| 印江| 修武县| 衡东县| 固始县| 松桃| 濉溪县| 嘉祥县| 封丘县| 利川市| 利川市| 新野县| 汉川市| 曲阳县| 固安县| 沁水县| 井冈山市| 鞍山市| 广南县| 雅江县| 定襄县| 綦江县| 枣阳市| 开鲁县| 徐水县| 岑溪市| 合川市| 自贡市| 家居| 山东省| 沈阳市| 通海县| 淮南市|