Home > Blockchain >  When I git push all files are update (even not changed), what am I doing wrong?
When I git push all files are update (even not changed), what am I doing wrong?

Time:12-20

I'm new to git, I know how to push changes when you're single on a project, but right now I'm in situation with three developers on one project. So I have a project which was downloaded as zip file directly from repository (not cloned), then I made a lot of changes and my colleague made some changes too at the same time and he pushed them. Now I need to pull his changes, merge them and push, but I have problems in the end, when I push files (successfully), all files update even that I didn't touch and change.

So here is my steps:

git init

then I manage remote repository:

git remote add origin <remote url>

and can check it:

git remote -v

and receive:

> origin  <remote url> (fetch)
> origin  <remote url> (push)

then I add files and commit changes:

git add .
git commit -m "Test"

then I'm trying to pull changes from repository:

git pull origin master

and get a message fatal: refusing to merge unrelated histories and type:

git pull origin master --allow-unrelated-histories

Then I have a message Please move or remove them before you merge. and I delete them and pull again:

git clean -f -d -x
git pull origin master

And get some merge conflicts, I fix them manually and again add files and commit:

git add .
git commit -m "Merge conflicts Test"

Finally I push files:

git push origin master

And what I see is that all files are updated with two variants(15 minutes ago and 10 minutes ago): push result of two commits

So first one (15min) on first commit and (10min) on second, but why first commit updates every file, does it happens because I didn't clone repository, right? If yes, how can I fix it?

CodePudding user response:

A safer approach would be to clone the remote repository, instead of initialize it locally and try to push.

Once cloned, you can import your work (done locally based on the initial zip archive, in another folder, where you did a lot of changes):

git config --global rebase.autostash true
git config --global pull.rebase true
git clone https://remote/url/reponame
cd reponame
git --work-tree=../otherfolder add .
git commit -m "Import my work"
git pull
# resolve conflict
git push

In other words, leave your local repository aside (where you tried a pull --allow-unrelated-histories, which is not a good idea).

And do everything from an official clone.

  • Related