Git confusion. "fatal: failed to open 'app/lang/en/homepage.php': File exists" - linux

The other day I had to have a full image restore of one of our production servers due to a problem encountered with git and not having any clue how to solve the issue. The standard workflow, which has worked for almost 2 years without a problem has been:
Make local changes
Commit
Finish feature (GitFlow)
Push to remote origin
Login to server, go to http root and issue the following command:
git pull master Version_1.x.x
However, this time instead of this working as usual I was presented with this error.
fatal: failed to open 'app/lang/en/homepage.php': File exists
That file was updated in dev as were several other files. I immediately got server monitoring notification that the website was no longer responding. So I loaded it up and I got a 404 error??
Returning to the console I did git status and was blown away with what was shown.
On branch master
Changed but not updated:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/views/layouts/landingBody.blade.php
modified: app/views/layouts/trailblazers.blade.php
modified: app/views/mobile/UI/landingBody.blade.php
modified: public/images/spashPage_full_new.jpg
Untracked files:
(use "git add <file>..." to include in what will be committed)
public/images/3rd_Party/
public/images/UI_bg_login_summer2015.jpg
public/images/spashPage_full_1024_summer2015.jpg
public/images/spashPage_full_1200_summer2015.jpg
public/images/spashPage_full_blur_summer2015.jpg
public/images/spashPage_full_summer2015.jpg
no changes added to commit (use "git add" and/or "git commit -a")
How is this possible that files have been changed in production and files that were part of the latest update were reporting as untracked files?
So I tried stashing the changes which predictably returned the following on the next git status
On branch master
nothing to commit (working directory clean)
I tried everything from reset hard to reset to a specific commit and it progressively got worse to the point I was getting.
I got errors such as
git reset --hard ORIG_HEAD
error: git checkout-index: unable to create file app/3rdParty/Mobile_Detect.php (File exists)
error: git checkout-index: unable to create file app/config/app.php (File exists)
Not knowing what else to do, I did a full restore from a snapshot. Now that I am back to the last backup, which was less than 16hrs old, and no other changes made since then I do a git status on the same production machine. Just to check before actually issuing another git pull command and messing everything up again. The following was result:
On branch master
Changed but not updated:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: public/.htaccess
Untracked files:
(use "git add <file>..." to include in what will be committed)
app/config/auth.php
app/config/cache.php
app/config/compile.php
app/config/database.php
app/config/remote.php
app/config/session.php
app/views/emails/
app/views/hello.php
bootstrap/compiled.php
readme.md
no changes added to commit (use "git add" and/or "git commit -a")
Again how is this possible? Nothing is ever done in production except git pull <local branch> <origin branch>, yet there are untracked files and modified files.
I have updates which need to be "pushed" into production but I can't have the website go down again. Not being a git expert makes this especially difficult.
I did check the git log on production and compared it with the origin, and dev and the commits all match up. This is all very perplexing.
Any help would be greatly appreciated.

The problem was within dropbox. The .gitignore file for one of the sub directories was removed and replaced with an alternate version and was unintentionally pushed in a previous release. The next time it was time to update everything was completely out of whack. Replacing the .gitignore file with the correct version and doing a hard reset, followed by a pull resolved the issue. Lesson: Dropbox can be dangerous when playing in the same sandbox as git.

Related

Git status content is different in different linux account

There are two accounts in linux server, root and super.
I can git pull to latest code by root account
I cannot git pull to latest code by super account
I found the status content is different by execute git status
super#api-dev:~/dnmp/www/localhost$ git status
On branch develop
Your branch is up to date with 'origin/develop'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
../../data/
../../docker-compose.yml
../../services/
../
nothing added to commit but untracked files present (use "git add" to track)
...
root#api-dev:~/dnmp/www/localhost# git status
On branch develop
Your branch is up to date with 'origin/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: composer.lock
no changes added to commit (use "git add" and/or "git commit -a")
There is a git repository root in ~/dnmp/
There is another git repository root in ~/dnmp/www/localhost
I want to change git status of super account to the same as root content.
Any idea to fix the difference?
git is different from other source control systems. When you clone a repository, it creates a local repository copy on your computer. So you have 1 copy as root, and another copy as super.
Then you can modify the files in your local copy, even commit these changes. But the main repository will not know of these until you push them into it.
So, when you run git status it shows you the state of the local repository, not the state of the main git repository.
To sync your local repositories with the main one, you can:
delete your local repository and clone from scratch.
pull the files from the main repository with git pull.
If you want to keep some changes you made locally, you will have to commit and push these up to the main repository first.
You can read on git, like this simple page: https://rogerdudler.github.io/git-guide/
More in depth sites exist to explain the whole of git, like:
https://www.atlassian.com/git/tutorials
https://www.freecodecamp.org/news/what-is-git-and-how-to-use-it-c341b049ae61/

How to commit changes on server and pull updates from code repository without conflict?

I pushed latest codes from my GitLab repository. The changes was coming from my local development machine. I've successfully done it using this commands:
git push
to push my latest changes to my GitLab repository. Now I pulled the updates on server but unfortunately it did not happen successfully since I have uncommitted changes from the server.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .htaccess
modified: composer.json
modified: composer.lock
Untracked files:
(use "git add <file>..." to include in what will be committed)
php.ini
php_errorlog
These changes makes my git pull failed thus need to commit it first before pulling the updates from GitLab repository. How should we commit it the right way to prevent conflict on server side.
This is actually the scenario:
First I push my changes from local development machine to Gitlab repository. git command git push
Second I pull code updates from Gitlab repository to my server. git command git pull
Third I get conflict due to uncommitted changes in server.
Error conflict: after done the second step.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .htaccess
modified: composer.json
modified: composer.lock
Untracked files:
(use "git add <file>..." to include in what will be committed)
php.ini
php_errorlog
NOTE : If multiple people are working on the same file, then there is more possibility of getting conflicts. It will be easy to resolve conflicts with Visual Studio Code Editor
Steps to resolve conflicts
Check whether all your change set are correct , validate once and remove /discard all the wanted files which you don't want to commit
Enter the command in current work folder git add .
Then check the staged file with the next command git status and validate once like whether the required file only got staged up.
Then do git stash, which will store your current code with another index
Now do git pull to pull the changes from the server, which will make your current working repository latest with server
Now do git stash pop , this will stash the changes which you have done
Since you have poped out your changes , if any conflict occurs check the changeset
if both are needed - do Accept Both,
if only your changes needed - do Accept Incoming,
if the current changes present in server is needed - Accept Current.
Again check git status, by this you can reverify whether only your changeset is correct
Now you can commit your changes to the server
Hope this would be helpful

After GIT commit, I did GIT push but the message said everything up-to-date

I'm new to Git. We're in Linux, and I just inherited someone's project family.
I recently did:
git add Bom.xml Bom.csv N.cpp makefile ../mm
git commit -a
(said On branch Bom, your branch is ahead of master by 2 commits. use git push to publish your local commits. Untracked files: list of things I don't want to commit anyway). Nothing added to commit but untracked files present.
then
git push
But it said everything up-to-date. I'm not sure where to look to see that my content is pushed up to my branch on the server. I know I had file changes since my last commit. It's a tough thing to search for the answer online. I looked at up-to-date too, and added the git add and the -a to my commit, but it still says up-to-date when I try to push.
Thanks!
Mich
Like the link you mentioned, make sure you have added the file you want to commit into the staging area. Each time you want to commit
run git status to check.
And then run git add file to add file to staging area.
Run git status to check whether the file is added to the stage.
Then run git commit -m "some message" to commit
run git log to check your commit history check whether you have committed successfully
then check your remote branch by running git branch -a
if your remote branch doesn't have your local branch branch-name
then run git push origin branch-name to push your local branch to remote.

Error on git patch using git am

When I try to perform a patch using:
git am 0001-someFile.patch
but I get this error:
error: patch failed: src/***/file.c:459
error: src/***/file.c: patch does not apply
Patch failed at 0001 someFile.patch
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
I am trying to manually merge the conflicts using:
git mergetool --tool=meld
But I am getting:
No files need merging
How can I solve this problem?
I am getting the name of the file which holds the error, but have no idea about the line (it's a big file)
Maybe there is a better way to perform such patching?
I'm in charge of handling all patching at my work. I've had this happen many times. A patch cannot be merged. The reason this is happening is because the master branch has changes that the patch did not take into account, which prevents it from patching correctly. From all my experience, this could be caused by several things:
The person who made the patch failed to pull the master branch and rebase master onto their development branch.
Between the time that the person pulled and the patch was applied enough changes were made to the master branch to stop the patch from applying due to too many conflicts.
The person patched incorrectly.
Here is the flow I've had the most success with. (This is assuming the person is developing on a branch other than master)
Make sure you've added all files and commited all changes.
git checkout master
git pull
git checkout {development branch}
git rebase master (this will bring the development branch up to speed with master)
git checkout -b {submission branch} master
git merge --squash --no-commit {development branch}
git commit -am "Commit Comment Here" (NOTE: This commit comment will be the name of the patch)
git format-patch origin..HEAD
That makes sure your patch is up to date with the origin master branch. Send that patch and hopefully the patch is applied before too many changes are made on the master.
You need to do a 3-way merge:
git am -3 0001-someFile.patch
git mergetool -t meld

How can I remove last two commits in git and get my commit 1 as changes in working directory?

Here is the scenario:
On a smallish Ubuntu web server I have a git server running. The website is checked out from git repository. I had a bulk of changes that I added and committed. Git diff showed 50+ code files updated and 20000+ image files. I did not paid much attention to this thinking these should be ignored, my fault. A bit stupid but I thought it was quickest to just commit all changes as a bulk. Let's call it commit A
# Commit A
git add .
git commit -m "Changes so far in this year"
I discovered that I forgot to exclude working/output files (huge number of generated images). Other than these files (around 20000) I had about 50+ files with code changes.
After reading online and git manual I understood that best bet was to update .gitignore and generate a list of files to remove and remove cached. This should remove from commit but not the local folder. Let this be commit B
# Commit B
vi .gitignore
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
git add .
git commit -m "Cleanup of generated files from commit history"
Trouble is that now my git push fails with following error
git push origin master
Counting objects: 19219, done.
error: pack-objects died of signal 9
error: pack-objects died with strange error
error: child process died of signal 9
error: died of signal 9
error: failed to push some refs to '/srv/gitrepositories/xxxx.git'
Answers on this question about error 9 suggests it might be due to git running out of memory.
My options?
Is commit A & commit B made up of huge
number of objects, which looking at the count above it seems?
Is there a better way to clean this mess up with possible option to remove commit A & commit B altogether from history and get my changes intact?
Idealy I want to go back to stage where my git diff reports only the 50+ code files. Images are now ignored by .gitignore
Can I delete a git commit but keep the changes? Is this what it sounds like? Can I do it twice for both commit A and commit B?
Yes, you can use git reset HEAD~2 to clear the last 2 commit from history permanently while keeping the changes in the working directory, then git push -f to force push your changed history to the remote.
If your repo is shared with others it's not advisable to change your commit history.

Resources