简体   繁体   English

通过 git 命令拉取和推送文件

[英]Pull and push files via git commands

I'm new in git and having queries in using git commands.我是 git 新手,对使用 git 命令有疑问。

I have created a git repo with two branches and I'm following the below procedures while cloning it into local:我创建了一个带有两个分支的 git repo,并且在将其克隆到本地时遵循以下过程:

 git clone URL
 git checkout -b dev
 git pull origin dev

After pulling the code, I will follow the below steps to add the files and commit:拉取代码后,我将按照以下步骤添加文件并提交:

git add <file path>
git commit -m "description"
git push origin dev

In the server end, I will run the below command in root directory:在服务器端,我将在根目录中运行以下命令:

git pull origin dev git pull origin dev

My doubt is that what happen if I run the pull command from server, the old code will be removed from server or it will just override?我的疑问是,如果我从服务器运行 pull 命令会发生什么,旧代码将从服务器中删除还是只是覆盖?

Could anyone please guide me?有人可以指导我吗?

git pull is to get the latest commits in the remote repository . git pull 是获取远程仓库中的最新提交。

git push will push all the commits in your local repository to remote repository ie server end . git push 会将本地存储库中的所有提交推送到远程存储库,即服务器端。

Infact git clone alone from the repository is sufficient , because cloning is done directly from the remote repository and hence the latest .事实上,单独从存储库中进行 git clone 就足够了,因为克隆是直接从远程存储库完成的,因此是最新的 .

What happened in this case here is that the previous line of codes from the server is been replaced by your local change(s) made when you push.在这种情况下发生的事情是,服务器上的前一行代码被您推送时所做的本地更改替换。 However, you can be able to see exactly the change you pushed as to the one in the server.但是,您可以准确地看到您推送到服务器中的更改。 It's always a good practice to always pull first before you commit and push your local changes.在提交和推送本地更改之前始终先拉取始终是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM